is.wholeNumber {omnibus} | R Documentation |
Test if a numeric value is a whole number
Description
Sometimes numeric values can appear to be whole numbers but are actually represented in the computer as floating-point values. In these cases, simple inspection of a value will not tell you if it is a whole number or not. This function tests if a number is "close enough" to an integer to be a whole number. Note that is.integer
will indicate if a value is of class integer (which if it is, will always be a whole number), but objects of class numeric
will not evaluate to TRUE
even if they are "supposed" to represent integers.
Usage
is.wholeNumber(x, tol = .Machine$double.eps^0.5)
Arguments
x |
A numeric or integer vector. |
tol |
Largest absolute difference between a value and its integer representation for it to be considered a whole number. |
Value
A logical vector.
See Also
Examples
x <- c(4, 12 / 3, 21, 21.1)
is.wholeNumber(x)
[Package omnibus version 1.2.13 Index]