Skip to content
Prev 67480 / 398506 Next

removing characters from a string

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.:
[1] "981"

[I'm really bad in regular expressions, and don't know how to construct
"non-numerics".]

Andy