Re: [R] Regex question

From: jim holtman <jholtman_at_gmail.com>
Date: Sun 29 Jan 2006 - 10:04:46 EST

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@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@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?

	[[alternative HTML version deleted]]

______________________________________________
R-help@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
Received on Sun Jan 29 10:12:05 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:14 EST