gsub('.+; (.+);.+','\\1',x)

or if you just want the value out:

gsub('.+; Surv\\(months\\): ([0-9]+);.+','\\1',x)

You can also look at strsplit:
> strsplit(x,';')
[[1]]
[1] "99-625: Cell type: S"        " Surv(months): 21"           "
STATUS(0=alive, 1=dead): 1"

> lapply(strsplit(x,';'),'[',2)
[[1]]
[1] " Surv(months): 21"

But i would follow David's second suggestion and just read them in with
sep=';' instead.


Justin

On Wed, Feb 29, 2012 at 11:24 AM, Fred G <bayespoker...@gmail.com> wrote:

> Computer Friends,
>
> with the following example lines:
>
> [107] "98-610: Cell type: S; Surv(months): 6; STATUS(0=alive, 1=dead): 1"
>
> [108] "99-625: Cell type: S; Surv(months): 21; STATUS(0=alive, 1=dead): 1"
>
> i want to be able to isolate the number of months of survival for each row.
>
> is there a regular expression that can find the first instance of a ";",
> delete everything in front of it-- and find the second instance of an ";"
> and delete everything behind it? in python there is a function line.find(),
> would be grateful to hear the R equiv; or, any other better alternatives to
> get the number of months of survival stored as a variable.
>
> Much Thank You!
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org 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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to