Re: [R] splitting a string / finding a numeric value within a string

2009-01-16 Thread Gabor Grothendieck
The first one replaces non-numerics with the empty string and the second one returns numerics directly: gsub("[^0-9]", "", "test_01.log") # or library(gsubfn) strapply("test_01.log", "[0-9]+")[[1]] On Fri, Jan 16, 2009 at 11:00 PM, Jörg Groß wrote: > Hi, > > I have this variable; > > > x <- c("

Re: [R] splitting a string / finding a numeric value within a string

2009-01-16 Thread Jorge Ivan Velez
Dear Jörg, Try this: > gsub("^.*['_']|[.].*$", "", "test_01.log") [1] "01" > as.numeric(gsub("^.*['_']|[.].*$", "", "test_01.log")) [1] 1 HTH, Jorge On Fri, Jan 16, 2009 at 11:00 PM, Jörg Groß wrote: > Hi, > > I have this variable; > > > x <- c("test_01.log") > > > and I want to extract th