Import Specific Row in R: Quick Guide

In R language, we can use the read.table() function to import data and select specific rows by specifying the parameter nrows. For example, if we want to import the 5th row of the file data.csv, we can use the following code:

data <- read.table("data.csv", header=TRUE, nrows=1, skip=4)

In the above code, setting header=TRUE indicates that the first row is the column name, nrows=1 means importing only 1 row of data, skip=4 signifies skipping the first 4 rows of data and starting the import from the 5th row. The imported data will be stored in the variable ‘data’.

bannerAds