[R] question

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Nov 19 10:44:27 CET 2003

Read the lines with readLines into a character vector
Remove the lines you don't want
Use read.table on a textConnection to the character vector

If the file were very large, use an anonymous file() connection instead
(but better use OS tools such as grep to clean up the file).

On Wed, 19 Nov 2003, Fuensanta Saura Igual wrote:

> Does anyone know how I can read from a .txt file the lines that are between
> two strings whose location is unknown?
> My problem is that I have a .txt file with data separated by a sentence,
> for example:
> 2.22 3.45
> 1.56 2.31
> pattern 1
> 4.67 7.91
> 3.34 2.15
> 5.32 3.88
> pattern 2
> ...
> I do not know the number of lines where these separating sentences are located,
> because the number of lines in between them can be random. If it was fixed, I 
> think I could use "read.table" using the option "skip", but in this case, I do 
> not know how I could manage to do that automatically.

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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list