Patrick E. McKnight
2001-Nov-13 21:32 UTC
[R] reading in data contingent upon a character at col 1
Greetings, I have a text file that is output from a statistics package that I would like to read into R. Since I have several hundred of these output files I would prefer not to edit them manually. The problem is that it has a ";" (without the quotes) as the first character for some lines - lines that I do not necessarily want to read in. Use of tr, sed, awk or any other unix command line utilities would not be suitable for this application. A sample of the file looks like this: ; Title of the run ; some other information ; subject var1 var2 var3 var4 000001 23 34 12 23 ; 000002 00 00 00 00 000003 15 18 30 29 ; 000004 00 00 00 00 000005 00 12 34 56 Essentially the commented out lines with the ";" characters were not estimated in the analysis so I do not want them to be read into the data frame. Is there a way to skip the line if it contains a ";" in column 1? If so, how might I accomplish this feat? Thanks in advance for your help. -- Cheers, Patrick -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian Ripley
2001-Nov-13 21:44 UTC
[R] reading in data contingent upon a character at col 1
On Tue, 13 Nov 2001, Patrick E. McKnight wrote:> Greetings, > > I have a text file that is output from a statistics package that I would like > to read into R. Since I have several hundred of these output files I would > prefer not to edit them manually. The problem is that it has a ";" (without > the quotes) as the first character for some lines - lines that I do not > necessarily want to read in. Use of tr, sed, awk or any other unix command > line utilities would not be suitable for this application. > > A sample of the file looks like this: > > ; Title of the run > ; some other information > ; subject var1 var2 var3 var4 > 000001 23 34 12 23 > ; 000002 00 00 00 00 > 000003 15 18 30 29 > ; 000004 00 00 00 00 > 000005 00 12 34 56 > > Essentially the commented out lines with the ";" characters were not > estimated in the analysis so I do not want them to be read into the data > frame. Is there a way to skip the line if it contains a ";" in column 1? If > so, how might I accomplish this feat? Thanks in advance for your help.We've anticipated your request! Take a look at ?read.table in R-devel. That has a `comment.char' argument. Just one warning: by default R-devel saves in a different format from 1.3.1, so if you want to transfer a workspace back, check the options on save. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Trent Piepho
2001-Nov-13 22:28 UTC
[R] reading in data contingent upon a character at col 1
On Tue, 13 Nov 2001, Patrick E. McKnight wrote:> necessarily want to read in. Use of tr, sed, awk or any other unix command > line utilities would not be suitable for this application.If you could use awk, it would work just fine for this. Tell R to open a pipe.. scan( pipe("awk '!/^;/' filename") ) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._