Determines whether each element of a character vector can be coerced to numeric.

isNumeral(c)

is.numeral(c)

Arguments

c

A vector of strings.

Value

A vector of logicals, NA where is.na(c).

Details

Checks element-wise as to whether each item in a vector of strings can be coerced to numeric.

Basics cribbed from http://rosettacode.org/wiki/Determine_if_a_string_is_numeric#R.

is.numeral() is deprecated.

Author

David Braze davebraze@gmail.com

Examples

x <- c('a', 'IX', 'twelve', '0001', '2', '3e1', '-4', '5.5', 'Inf', NA) data.frame(x, isNumeral(x), as.numeric(x))
#> Warning: NAs introduced by coercion
#> x isNumeral.x. as.numeric.x. #> 1 a FALSE NA #> 2 IX FALSE NA #> 3 twelve FALSE NA #> 4 0001 TRUE 1.0 #> 5 2 TRUE 2.0 #> 6 3e1 TRUE 30.0 #> 7 -4 TRUE -4.0 #> 8 5.5 TRUE 5.5 #> 9 Inf TRUE Inf #> 10 <NA> NA NA