Re: [R] separate numbers from chars in a string

2014-07-31 Thread arun
If you have some variations of the order of numbers followed by chars, library(stringr) v1 - c(absdfds0213451ab, 123abcs4145) pattern=c([A-Za-z]+, \\d+) do.call(`Map`,c(c,lapply(pattern, function(.pat) str_extract_all(v1, .pat #[[1]] #[1] absdfds ab  0213451 #[[2]] #[1] abcs 123  4145

Re: [R] separate numbers from chars in a string

2014-07-31 Thread Uwe Ligges
On 31.07.2014 04:46, carol white wrote: There are some level of variation either chars followed by numbers or chars, numbers, chars Perhaps, I should use gsub as you suggested all and if the string is composed of chars followed by numbers, it will return the 3rd part empty? Please read

Re: [R] separate numbers from chars in a string

2014-07-31 Thread Marc Schwartz
On Jul 31, 2014, at 3:17 AM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 31.07.2014 04:46, carol white wrote: There are some level of variation either chars followed by numbers or chars, numbers, chars Perhaps, I should use gsub as you suggested all and if the string is

[R] separate numbers from chars in a string

2014-07-30 Thread carol white
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,

Re: [R] separate numbers from chars in a string

2014-07-30 Thread Rui Barradas
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:

Re: [R] separate numbers from chars in a string

2014-07-30 Thread Marc Schwartz
On Jul 30, 2014, at 3:13 PM, carol white wht_...@yahoo.com wrote: 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

Re: [R] separate numbers from chars in a string

2014-07-30 Thread Uwe Ligges
On 30.07.2014 22:13, carol white wrote: 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,

Re: [R] separate numbers from chars in a string

2014-07-30 Thread carol white
There are some level of variation either chars followed by numbers or chars, numbers, chars Perhaps, I should use gsub as you suggested all and if the string is composed of chars followed by numbers, it will return the 3rd part empty? Regards, Carol On Wednesday, July 30, 2014 10:52 PM,