[R] (no subject)
ian kennedy
ian.kennedy at hc-sc.gc.ca
Thu May 20 22:12:21 CEST 2010
Here's another possibility:
> x <- c("Apple12","HP42","Dell91")
> strsplit(x,"(?<=\\D)(?=\\d)", perl=TRUE)
[[1]]
[1] "Apple" "12"
[[2]]
[1] "HP" "42"
[[3]]
[1] "Dell" "91"
Krishna Tateneni <tateneni at gmail.com> writes:
> Greetings,
>
> I have a vector of values that are a word followed by a number, e.g., x =
> c("Apple12","HP42","Dell91"). The goal is to split this vector into two
> vectors such that the first vector contains just the words and the second
> contains just the numbers. I cannot use strsplit (or at least I do not
> know how) as there is no obvious separator.
>
> I can use sub to create a separator, e.g., y = sub("([[:digit:]])","
> \\1",x), and then use strsplit, but I thought more experienced R users may
> have a better solution. I've spent some time with Google, but not turned
> up anything so far.
>
> Many thanks,
> --Krishna
More information about the R-help
mailing list