try this:
> str <- c("14.XYZ", "15.ABCDE", "16.dkieowo", "120.EIDKAI")
> x <- gsub("[^0-9]", "", str)
> x
[1] "14" "15" "16" "120"
> as.integer(x)
[1] 14 15 16 120
>
On Fri, Sep 16, 2011 at 5:13 AM, Karl Weinmayer wrote:
> Dear all,
>
>
>
> I have a vector, which looks about like this:
>
Hi Karl,
both strategies are possible using gsub:
gsub("([0-9]*).*","\\1",str) #extract numbers
gsub("[^0-9]","",str) #remove all non-numeric characters
wrap it nicely in an "as.numeric" call to get numeric values.
cheers.
Am 16.09.2011 11:13, schrieb Karl Weinmayer:
> Dear all,
>
>
>
> I h
2 matches
Mail list logo