Re: [R] Better use with gsub

2014-08-01 Thread Marek Szatkowski
How about: x <- as.numeric(sub("^S([0-9]+):([0-9]+)$", "\\1", xx)) y <- as.numeric(sub("^S([0-9]+):([0-9]+)$", "\\2", xx)) 2014-08-01 16:46 GMT+02:00 Doran, Harold : > I have done an embarrassingly bad job using a mixture of gsub and strsplit > to solve a problem. Below is sample code showing

Re: [R] Better use with gsub

2014-08-01 Thread Marc Schwartz
On Aug 1, 2014, at 9:46 AM, Doran, Harold wrote: > I have done an embarrassingly bad job using a mixture of gsub and strsplit to > solve a problem. Below is sample code showing what I have to start with (the > vector xx) and I want to end up with two vectors x and y that contain only > the dig

Re: [R] Better use with gsub

2014-08-01 Thread arun
Forgot about as.numeric.  sapply(str_extract_all(xx, perl('(?<=[A-Z]|\\:)\\d+')),as.numeric) [,1] [,2] [,3] [,4] [,5] [,6] [1,]   24   24   24   24   24   24 [2,]   57   86  119  129  138  163 On Friday, August 1, 2014 10:59 AM, arun wrote: You could try: library(stringr)   simplify

Re: [R] Better use with gsub

2014-08-01 Thread arun
You could try: library(stringr)   simplify2array(str_extract_all(xx, perl('(?<=[A-Z]|\\:)\\d+'))) [,1] [,2] [,3]  [,4]  [,5]  [,6] [1,] "24" "24" "24"  "24"  "24"  "24" [2,] "57" "86" "119" "129" "138" "163" A.K. On Friday, August 1, 2014 10:49 AM, "Doran, Harold" wrote: I have done an

Re: [R] Better use with gsub

2014-08-01 Thread Gabor Grothendieck
On Fri, Aug 1, 2014 at 10:46 AM, Doran, Harold wrote: > I have done an embarrassingly bad job using a mixture of gsub and strsplit to > solve a problem. Below is sample code showing what I have to start with (the > vector xx) and I want to end up with two vectors x and y that contain only > the

[R] Better use with gsub

2014-08-01 Thread Doran, Harold
I have done an embarrassingly bad job using a mixture of gsub and strsplit to solve a problem. Below is sample code showing what I have to start with (the vector xx) and I want to end up with two vectors x and y that contain only the digits found in xx. Any regex users with advice most welcome