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("
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
2 matches
Mail list logo