I have very big .csv file, it's around a few GB.
I want to read first few thousand lines of it. Is there any method to do this efficiently?
Use the nrows
argument in read.csv(...)
df <- read.csv(file="my.large.file.csv",nrows=2000)
There is also a skip=
parameter that tells read.csv(...)
how many lines to skip before you start reading.
If your file is that large you might be better off using fread(...)
in the data.table package. Same arguments.
If you're on UNIX or OS/X, you can use the command line:
head -n 1000 myfile.csv > myfile.head.csv
Then just read it in R like normal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With