Numeric vectors
Coerces objects to class "numeric", and checks if an object is numeric.
asNumeric(x) possibleNumeric(x) wholeNumeric(x)
x |
A vector of values |
Unlike the function as.numeric()
from the base
package, the function asNumeric()
coerces to numeric without a warning if
any values are not numeric. All such values are considered NA missing.
The function possibleNumeric()
tests if the values in a vector are possibly
numeric, irrespective of their storing as character or numbers.
Function wholeNumeric()
tests if numbers in a vector are whole (round) numbers.
Whole numbers are different from “integer” numbers (which have special memory
representation), and consequently the function is.integer()
tests
something different, how numbers are stored in memory (see the description of function
double()
for more details).
Adrian Dusa
x <- c("-.1", " 2.7 ", "B") asNumeric(x) # (-0.1, 2.7, NA) and no warning possibleNumeric(x) # FALSE possibleNumeric(c("1", 2, 3)) # TRUE is.integer(1) # FALSE # Signaling an integer in R is.integer(1L) # TRUE wholeNumeric(1) # TRUE
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.