[R] Extract Element of String with R's Regex
Edward Wijaya
ewijaya at gmail.com
Fri Aug 1 08:13:58 CEST 2008
Hi,
I have this string, in which I want to extract some of it's element:
> x <- "Best-K Gene 11340 211952_at RANBP5 Noc= 3 - 2 LL= -963.669 -965.35"
yielding this array
[1] "211952_at" "RANBP5" "2"
In Perl we would do it this way:
__BEGIN__
my @needed =();
my $str = "Best-K Gene 11340 211952_at RANBP5 Noc= 3 - 2 LL=
-963.669 -965.35";
$str =~ /Best-K Gene \d+ (\w+) (\w+) Noc= \d - (\d) LL= (.*)/;
push @needed, ($1,$2,$3);
__END___
How can we achieve this with R?
- E.W.
More information about the R-help
mailing list