Reputation: 6157
Is there any simple R function to read specific lines from text files (*.txt or especially *.csv) without reading the whole file into memory? I would like to read in only chosen lines of the file, for example reading only lines with x1==b
:
x1 x2 x3
a 1 1
a 2 2
b 2 3
b 1 4
a 2 1
->
x1 x2 x3
b 2 3
b 1 4
maybe some Perl tool for R, but is it easy (for R user)?
Upvotes: 1
Views: 218
Reputation: 368619
The default read.*
functions all read everything by default. So one option is to use an external filter --- as e.g. an awk or sed script, or a grep expression --- and then to read via read.table()
from that stream after having filtered.
Upvotes: 2