[R] regular expressions : extracting numbers

2007-07-30 Thread GOUACHE David
Hello all, I have a vector of character strings, in which I have letters, numbers, and symbols. What I wish to do is obtain a vector of the same length with just the numbers. A quick example - extract of the original vector : lema, rb 2% rb 2% rb 3% rb 4% rb 3% rb 2%,mineuse rb rb rb 12 rb rj

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Romain Francois
Bonjour David, What about one of these : R gsub( [^[:digit:]], , x ) or using perl regular expressions: R gsub( \\D, , x, perl = T ) Cheers, Romain GOUACHE David wrote: Hello all, I have a vector of character strings, in which I have letters, numbers, and symbols. What I wish to do is

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread jim holtman
Is this what you want: x [1] lema, rb 2% rb 2% rb 3% rb 4% rb 3% rb 2%,mineuse [7] rbrbrb 12 rb rj 30%rb [13] rbrb 25%rbrb rbrj, rb gsub([^0-9]*([0-9]*)[^0-9]*, \\1, x) [1] 2 2 3

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Vladimir Eremeev
GOUACHE David wrote: Hello all, I have a vector of character strings, in which I have letters, numbers, and symbols. What I wish to do is obtain a vector of the same length with just the numbers. A quick example - extract of the original vector : lema, rb 2% rb 2% rb 3% rb 4% rb 3%

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Christian Ritz
Dear David, does the following work for you? sVec - c(lema, rb 2%, rb 2%, rb 3%, rb 4%, rb 3%, rb 2%,mineuse, rb, rb, rb 12, rb, rj 30%, rb, rb, rb 25%, rb, rb, rb, rj, rb) reVec - regexpr([[:digit:]]+, sVec) # see ?regex for details on '[:digit:]' and '+' substr(sVec ,start = reVec,

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Marc Schwartz
On Mon, 2007-07-30 at 13:58 +0200, GOUACHE David wrote: Hello all, I have a vector of character strings, in which I have letters, numbers, and symbols. What I wish to do is obtain a vector of the same length with just the numbers. A quick example - extract of the original vector : lema,

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Gabor Grothendieck
I assume if you want the components to be NA then you really intend the result to be a numeric vector. The following replaces all non-digits with (thereby removing them) and then uses as.numeric to convert the result to numeric. Just omit the conversion if you want a character vector result:

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Jacques VESLOT
gsub( , , gsub(%, , gsub([a-z], , c(tr3,jh40%qs dqd [1] 3 40 Jacques VESLOT INRA - Biostatistique Processus Spatiaux Site Agroparc 84914 Avignon Cedex 9, France Tel: +33 (0) 4 32 72 21 58 Fax: +33 (0) 4 32 72 21 84 GOUACHE David a écrit : Hello all, I have a vector of character

Re: [R] regular expressions : extracting numbers

2007-07-30 Thread Kuhn, Max
] regular expressions : extracting numbers Hello all, I have a vector of character strings, in which I have letters, numbers, and symbols. What I wish to do is obtain a vector of the same length with just the numbers. A quick example - extract of the original vector : lema, rb 2% rb 2% rb 3% rb 4% rb