is.wholeNumber | R Documentation |
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.
is.wholeNumber(x, tol = .Machine$double.eps^0.5)
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. |
A logical vector.
is.integer
x <- c(4, 12 / 3, 21, 21.1)
is.wholeNumber(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.