Read.csv Read a specific line

How can we read certain lines in R using the read.csv command? Let's say if I have a CSV file with 10 rows of data, and I just want to read the 5th row of data, I tried to do the following, but it doesn't seem to work:

myFile <- "MockData.csv" myData <- read.csv(myFile, row.names=5) myData 

Thanks!

+4
source share
2 answers

Try:

 myData <- read.csv(myFile, nrows=1, skip=4) 
+13
source

To read from the second line to the bottom of the file line by line (assuming that the first line is the heading and can be omitted), what was done, as such:

 myFile <- "MockData.csv" myData <- read.csv(myFile, skip=0, nrows=1) 

And then:

 myData <- read.csv(myFile, skip=1, nrows=1) 

The following are:

 myData <- read.csv(myFile, skip=2, nrows=1) 

And so on...

+2
source

Source: https://habr.com/ru/post/1489240/


All Articles