Skip to content
Prev 286837 / 398502 Next

regular expression

On Wed, Feb 29, 2012 at 2:24 PM, Fred G <bayespokerguy at gmail.com> wrote:
This extracts all the numeric fields:

# sample data
Lines <- c("98-610: Cell type: S; Surv(months): 6; STATUS(0=alive, 1=dead): 1",
"99-625: Cell type: S; Surv(months): 21; STATUS(0=alive, 1=dead): 1")

library(gsubfn)
strapply(Lines, "(\\d+);", as.numeric, simplify = TRUE)


# We can also get all numeric fields in case that is of interest:

strapply(Lines, "\\d+", as.numeric, simplify = rbind)