[R] Regex question
Andrej Kastrin
andrej.kastrin at siol.net
Sun Jan 29 00:28:30 CET 2006
jim holtman wrote:
> Is this what you want?
>
> > result <- readLines('/tempxx.txt')
> > result
> [1] "*NEW RECORD" "*ID-001" "*AB-text" "" "*NEW RECORD"
> [6] "*ID-002" "*AB-text"
> > result <- result[grep('^.ID-', result)] # select only ID lines
> > result
> [1] "*ID-001" "*ID-002"
> > sub('^.ID-', '', result)
> [1] "001" "002"
>
>
>
> On 1/28/06, *Andrej Kastrin* <andrej.kastrin at siol.net
> <mailto:andrej.kastrin at siol.net>> wrote:
>
> Dear R useRs,
>
> is there any simple, build in function to match specific regular
> expression in data file and write it to a vector. I have the
> following
> text file:
>
> *NEW RECORD
> *ID-001
> *AB-text
>
> *NEW RECORD
> *ID-002
> *AB-text
> etc.
>
> Now I have to match all ID fields and print them to a vector:
> 001
> 002
> etc.
>
> I know that this is very simple with Perl or R-Perl interface, but if
> possible, I want to do that 'on the hard way'.
>
> Cheers, Andrej
>
> ______________________________________________
> R-help at stat.math.ethz.ch <mailto:R-help at 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
>
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 247 0281
>
> What the problem you are trying to solve?
I'm forever indepted to you for this.
Cheers, Andrej
More information about the R-help
mailing list