[R] R input file scanning

Gabor Grothendieck ggrothendieck at myway.com
Fri Nov 7 14:18:28 CET 2003



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




More information about the R-help mailing list