[R] regex find anything which is not a number
John McKown
john.archie.mckown at gmail.com
Thu Mar 12 20:52:43 CET 2015
On Thu, Mar 12, 2015 at 2:43 PM, Steve Taylor <steve.taylor at aut.ac.nz> wrote:
> How about letting a standard function decide which are numbers:
>
> which(!is.na(suppressWarnings(as.numeric(myvector))))
>
> Also works with numbers in scientific notation and (presumably) different decimal characters, e.g. comma if that's what the locale uses.
One problem is that Adrian wanted, for some reason, to exclude numbers
such as "2." but accept "2.0" . That is, no unnecessary trailing
decimal point. as.numeric() will not fail on "2." since that is a
number. The example grep() specifically excludes this by requiring at
least one digit after any decimal point.
--
He's about as useful as a wax frying pan.
10 to the 12th power microphones = 1 Megaphone
Maranatha! <><
John McKown
More information about the R-help
mailing list