[R] separate numbers from chars in a string

Rui Barradas ruipbarradas at sapo.pt
Wed Jul 30 22:49:01 CEST 2014


Hello,

Maybe ?gregexpr and ?regmatches. SOmething like the following.


m1 <- gregexpr("[a-z]+","absdfds0213451ab")
regmatches("absdfds0213451ab", m1)

m2 <- gregexpr("[0-9]+","absdfds0213451ab")
regmatches("absdfds0213451ab", m2)


Hope this helps,

Rui Barradas

Em 30-07-2014 21:13, carol white escreveu:
> Hi,
> 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] 1
>
>
>   grep("[0-9]","absdfds0213451ab", ignore.case=T)
> [1] 1
>
> Thanks
>
> Carol
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> 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 mailing list