Re: [R] Reading a csv file row by row

From: ronggui <ronggui.huang_at_gmail.com>
Date: Fri 06 Apr 2007 - 13:19:24 GMT

And _file()_ is helpful in such situation.

R/S-PLUS Fundamentals and Programming Techniques by Thomas Lumley has something relavant in page 185 (total page is 208).

I believe you can find it by googling.

On 4/6/07, Martin Becker <martin.becker@mx.uni-saarland.de> wrote:
> readLines (which is mentioned in the "See also" section of ?scan with
> the hint "to read a file a line at a time") should work.
>
> Regards,
> Martin
>
> Yuchen Luo schrieb:
> > Hi, my friends.
> > When a data file is large, loading the whole file into the memory all
> > together is not feasible. A feasible way is to read one row, process it,
> > store the result, and read the next row.
> >
> >
> > In Fortran, by default, the 'read' command reads one line of a file, which
> > is convenient, and when the same 'read' command is executed the next time,
> > the next row of the same file will be read.
> >
> > I tried to replicate such row-by-row reading in R.I use scan( ) to do so
> > with the "skip= xxx " option. It takes only seconds when the number of the
> > rows is within 1000. However, it takes hours to read 10000 rows. I think it
> > is because every time R reads, it needs to start from the first row of the
> > file and count xxx rows to find the row it needs to read. Therefore, it
> > takes more time for R to locate the row it needs to read.

> >
> > Is there a solution to this problem?
> >
> > Your help will be highly appreciated!
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Ronggui Huang
Department of Sociology
Fudan University, Shanghai, China

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri Apr 06 23:24:48 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 06 Apr 2007 - 14:30:55 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.