[R] separate numbers from chars in a string
ligges at statistik.tu-dortmund.de
Wed Jul 30 23:05:11 CEST 2014
On 30.07.2014 22:13, carol white wrote:
> If I have a string of consecutive chars followed by consecutive numbers and then chars, like "absdfds0213451ab", how to separate the consecutive chars from consecutive numbers?
> grep doesn't seem to be helpful
> grep("[a-z]","absdfds0213451ab", ignore.case=T)
>  1
> grep("[0-9]","absdfds0213451ab", ignore.case=T)
>  1
I'd propose something along:
result <- gsub("^([[:alpha:]]+)([[:digit:]]+)([[:alpha:]]+)$",
If you have lots of these strings, you can convert all of them and then
do.call("rbind", strsplit(result, "-"))
or some such.
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help