Message-ID: <425BC9B3.3040405@lancaster.ac.uk>
Date: 2005-04-12T13:14:27Z
From: Barry Rowlingson
Subject: removing characters from a string
In-Reply-To: <39B6DDB9048D0F4DAD42CB26AAFF0AFA076D9D@usctmx1106.merck.com>
Liaw, Andy wrote:
> 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".]
>
Use a ^ to negate a character range:
> gsub("[^0-9]", "", "aB9c81")
[1] "981"
Baz