Read lines by number from a large file

后端 未结 5 682
有刺的猬
有刺的猬 2020-12-13 02:44

I have a file with 15 million lines (will not fit in memory). I also have a small vector of line numbers - the lines that I want to extract.

How can I read-out the l

5条回答
  •  旧巷少年郎
    2020-12-13 03:49

    If it's a binary file

    Some discussion is here: Reading in only part of a Stata .DTA file in R

    If it's a CSV or other text file

    If they are contiguous and at the top of the file, just use the ,nrows argument to read.csv or any of the read.table family. If not, you can combine the ,nrows and the ,skip arguments to repeatedly call read.csv (reading in a new row or group of contiguous rows with each call) and then rbind the results together.

提交回复
热议问题