Skip to content

removing characters from a string

4 messages · Liaw, Andy, Deepayan Sarkar, Barry Rowlingson +1 more

#
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
#
On Tuesday 12 April 2005 08:03, Liaw, Andy wrote:
(So am I, but) perhaps "[^0-9]".

Deepayan
#
Liaw, Andy wrote:
Use a ^ to negate a character range:

 > gsub("[^0-9]", "", "aB9c81")
[1] "981"

Baz
#
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