[R] Splitting strings

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Thu Aug 23 13:00:41 CEST 2007


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" <collins.gs at gmail.com>
To: <r-help at 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
> d        48
> d        67
> dnc     37
> a        75
> d        10
> a        78
> d        31
> d        55
> d        1
>
> I've tried various strsplit approaches but nothing has done what I 
> need.
>
> thanks in advance
>
> Gary
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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



More information about the R-help mailing list