You can use readLines() on a file connection to read line by line and throw out the header stuff. Once you get to the point where the data start, you can use read.table() (or something similar). -roger Mathieu Drapeau wrote:> Hi, > I would like to know how can I solve my problem... > I want to load some data (surrounded by a tag) that are stored in a > file that contains also some scrap (header and descriptions) that I > want to skip. How can I do that? > > Thanks, > Mathieu > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
If the portion of the file that you want to read is "rectangular" (same number of fields in all lines and same type of data in each column), you can use either read.table() or scan() and supply the skip= argument to skip over the headers you don't want to read in. HTH, Andy> From: Mathieu Drapeau [mailto:mathieu.drapeau at bioneq.qc.ca] > > Hi, > I would like to know how can I solve my problem... > I want to load some data (surrounded by a tag) that are > stored in a file > that contains also some scrap (header and descriptions) that > I want to > skip. How can I do that? > > Thanks, > Mathieu > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help >
Hi, I would like to know how can I solve my problem... I want to load some data (surrounded by a tag) that are stored in a file that contains also some scrap (header and descriptions) that I want to skip. How can I do that? Thanks, Mathieu
Assuming the start tag contains the word "start" and the end tag contains the word "end" you could do this: lines <- readLines( "input.txt" ) # lines is a vector of lines g <- grep( "start|end", lines ) # positions of tags lines <- lines[ seq( g[1]+1, g[2]-1 ) ] mydata <- read.table( textConnection(lines), head=TRUE ) If the scrap only appears before and not after the data then you could shorten this to: lines <- readLines( "input.txt" ) # lines is a vector of lines g <- grep( "start", lines ) # position of tag mydata <- read.table( textConnection(lines), skip=g[1], head=TRUE ) --- Date: Thu, 06 Nov 2003 21:53:08 -0500 From: Mathieu Drapeau <mathieu.drapeau at bioneq.qc.ca> To: <r-help at stat.math.ethz.ch> Subject: [R] R input file scanning Hi, I would like to know how can I solve my problem... I want to load some data (surrounded by a tag) that are stored in a file that contains also some scrap (header and descriptions) that I want to skip. How can I do that? Thanks, Mathieu