[R] Splitting strings

2007-08-23 Thread Gary Collins
I'm having a Thursday morning mental block, any suggestions on the following
would be most appreciated...

I have (as an example)

surgery = c(d48,  d67,  dnc37,  a75,  d10,  a78,  d31,
d55,  d1)

before each number part the possibilities are c(a, d, dnc), I'm trying
to split each element in surgery so that I have,

status time
d48
d67
dnc 37
a75
d10
a78
d31
d55
d1

I've tried various strsplit approaches but nothing has done what I need.

thanks in advance

Gary

[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Splitting strings

2007-08-23 Thread Dimitris Rizopoulos
one way is the following:

data.frame(status = gsub([0-9], , surgery),
time = gsub([a-z], , surgery))


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: Gary Collins [EMAIL PROTECTED]
To: r-help@stat.math.ethz.ch
Sent: Thursday, August 23, 2007 10:03 AM
Subject: [R] Splitting strings


 I'm having a Thursday morning mental block, any suggestions on the 
 following
 would be most appreciated...

 I have (as an example)

 surgery = c(d48,  d67,  dnc37,  a75,  d10,  a78,  d31,
 d55,  d1)

 before each number part the possibilities are c(a, d, dnc), 
 I'm trying
 to split each element in surgery so that I have,

 status time
 d48
 d67
 dnc 37
 a75
 d10
 a78
 d31
 d55
 d1

 I've tried various strsplit approaches but nothing has done what I 
 need.

 thanks in advance

 Gary

 [[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
 and provide commented, minimal, self-contained, reproducible code.
 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Splitting strings

2007-08-23 Thread Gabor Grothendieck
This applies the indicated perl-style regular expression where the
first backreference (\\D+) is the non-digits and the second
backreference (\\d+) is the digits.

The two backreferences, but not the entire matched pattern itself,
are passed as arguments x and y to the function whose body is the
right hand side of the formula in the third argument.

That is then simplified using rbind to give the result.

library(gsubfn)
strapply(surgery, (\\D+)(\\d+), ~ list(lets = x, nums = as.numeric(y)),
   backref = -2, perl = TRUE, simplify = rbind)

More on gsubfn at
  http://gsubfn.googlecode.com


On 8/23/07, Gary Collins [EMAIL PROTECTED] wrote:
 I'm having a Thursday morning mental block, any suggestions on the following
 would be most appreciated...

 I have (as an example)

 surgery = c(d48,  d67,  dnc37,  a75,  d10,  a78,  d31,
 d55,  d1)

 before each number part the possibilities are c(a, d, dnc), I'm trying
 to split each element in surgery so that I have,

 status time
 d48
 d67
 dnc 37
 a75
 d10
 a78
 d31
 d55
 d1

 I've tried various strsplit approaches but nothing has done what I need.

 thanks in advance

 Gary

[[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
 and provide commented, minimal, self-contained, reproducible code.


__
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
and provide commented, minimal, self-contained, reproducible code.