[R] removing characters from a string
Bill West
wjwest at CLEMSON.EDU
Tue Apr 12 15:15:13 CEST 2005
gsub("[^0-9]","","ab9c81")
HTH
--Bill
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Liaw, Andy
Sent: Tuesday, April 12, 2005 9:03 AM
To: 'Vivek Rao'; r-help at stat.math.ethz.ch
Subject: RE: [R] removing characters from a string
Just gsub() non-numerics with ""; e.g.:
> gsub("[a-zA-Z]", "", "aB9c81")
[1] "981"
[I'm really bad in regular expressions, and don't know how to construct
"non-numerics".]
Andy
More information about the R-help
mailing list