On Tue, Sep 27, 2011 at 5:49 PM, Michael Karol <mka...@syntapharma.com> wrote: > R Experts: > > > > I am trying to isolate the numeric value of day from a string that might > look like "Cycle 1 Day 8" or "Cycle 12 Day 15". > > > > In essence, what I need is a function that can look at a character > string and tell me the location within the string where it matches with > a given string. In this case, where within "Cycle 12 Day 15" is the > text "Day" located. > > > > The following works in S+, but I haven't been able to locate a function > within R that does what regMatchPos does in S+. >
This extracts the numbers from each string converting them to numeric: library(gsubfn) x <- c("Cycle 1 Day 8", "Cycle 12 Day 15") nums <- strapply(x, "\\d+", as.numeric, simplify = TRUE) which gives: > nums [,1] [,2] [1,] 1 12 [2,] 8 15 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ 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.