View source: R/is.wholenumber.R
| is.wholenumber | R Documentation |
Checks whether an object is numeric and if so, are all the elements whole numbers, to a given tolerance.
is.wholenumber(x, tolerance = .Machine$double.eps^0.5)
x |
The object to be tested. |
tolerance |
Numeric |
The object x is first tested to see if it is numeric. If not
the function returns 'FALSE'. Then if all the elements of
x are whole numbers to within the tolerance given by
tolerance the function returns 'TRUE'. If not it returns
'FALSE'.
Either 'TRUE' or 'FALSE' depending on the result of the
test.
David Scott d.scott@auckland.ac.nz.
Based on a post by Tony Plate <tplate@acm.org> on R-help.
is.wholenumber(-3:5) # TRUE
is.wholenumber(c(0,0.1,1.3,5)) # FALSE
is.wholenumber(-3:5 + .Machine$double.eps) # TRUE
is.wholenumber(-3:5 + .Machine$double.eps^0.5) # FALSE
is.wholenumber(c(2L,3L)) # TRUE
is.wholenumber(c("2L","3L")) # FALSE
is.wholenumber(0i ^ (-3:3)) # FALSE
is.wholenumber(matrix(1:6, nrow = 3)) # TRUE
is.wholenumber(list(-1:3,2:6)) # FALSE
is.numeric(list(-1:3,2:6)) # FALSE
is.wholenumber(unlist(list(-1:3,2:6))) # TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.