[R] Extract Element of String with R's Regex

2008-08-01 Thread Edward Wijaya
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

Re: [R] Extract Element of String with R's Regex

2008-08-01 Thread Simon Blomberg
How about: unlist(strsplit(x, split= ))[c(4:5,10)] That perl script looks like a good reason to avoid perl. Simon. On Fri, 2008-08-01 at 15:13 +0900, Edward Wijaya wrote: Hi, I have this string, in which I want to extract some of it's element: x - Best-K Gene 11340 211952_at RANBP5

Re: [R] Extract Element of String with R's Regex

2008-08-01 Thread Stephen Tucker
] Extract Element of String with R's Regex How about: unlist(strsplit(x, split= ))[c(4:5,10)] That perl script looks like a good reason to avoid perl. Simon. On Fri, 2008-08-01 at 15:13 +0900, Edward Wijaya wrote: Hi, I have this string, in which I want to extract some of it's element: x

Re: [R] Extract Element of String with R's Regex

2008-08-01 Thread Gabor Grothendieck
On Fri, Aug 1, 2008 at 7:31 AM, Stephen Tucker [EMAIL PROTECTED] wrote: In the example below, a straight application of strsplit() is probably the simplest solution. In a more general case where it may be desirable to match patterns, a combination of sub() or gsub() with strsplit() might do