Have you tried read.table() and the similar functions? I think they would provide a much more simple solution for your problem.
HTH, Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney > -----Oorspronkelijk bericht----- > Van: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Namens Yuchen Luo > Verzonden: woensdag 29 augustus 2007 19:41 > Aan: r-help@stat.math.ethz.ch > Onderwerp: [R] How to signal the end of the table? > > I am using a "for" loop to read a table row by row and I have > to specify how many records are there in the table. I need to > read row by row because the table is huge and the memory not > large enough for the whole table.: > > > > number.of.records=100 > > > > fp=file("abc.csv","r") > > pos=seek(fp, rw="read") > > for (i in 1:number.of.record){ > > current.row=scan(file=fp, sep=',', what=list(count=1, > cusip6="", idate=1, spread=1.1, vol252=1.1, vol1000=1.1, > st_debt=1.1, lt_debt=1.1 , total_liab= > 1.1, cr=1.1, shrout=1.1, prc=1.1, mkt_cap=1.1, rtng=1.1, > sec=1.1, cr3m=1.1, > cr5y=1.1, ust3m=1.1, ust5y=1.1), flush=TRUE, nlines=1,quiet=T) > > ... > > } > > > > I need to know the number of records in the table and put it > in the variable named "number.of.records". When I have a new > table that I do not know how many records it has, I use excel > to open the file to figure it out and put it in variable " > number.of.records". I often have many tables to try and every > one of them has thousands of records----it takes a lot of > time and trouble to adjust the code every time I read a > different table. > > > > I am wondering if I can change the "for" loop to a "while" loop: > > > > while (the end of the table has not been reached) > > { > > current.row=scan(file=fp, sep=',', what=list(count=1, > cusip6="", idate=1, spread=1.1, vol252=1.1, vol1000=1.1, > st_debt=1.1, lt_debt=1.1 , total_liab= > 1.1, cr=1.1, shrout=1.1, prc=1.1, mkt_cap=1.1, rtng=1.1, > sec=1.1, cr3m=1.1, > cr5y=1.1, ust3m=1.1, ust5y=1.1), flush=TRUE, nlines=1,quiet=T) > > ... > > } > > > The problem is how to articulate "while (the end of the table > has not been reached)", or equivalently, how to signal the > end of the table? > > Best Wishes > Yuchen Luo > > [[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.