Skip to content

Instantly share code, notes, and snippets.

@aammd
Created March 29, 2016 17:28
Show Gist options
  • Save aammd/1dce9fb8aab4ee6eb308b8f222ce2fbe to your computer and use it in GitHub Desktop.
Save aammd/1dce9fb8aab4ee6eb308b8f222ce2fbe to your computer and use it in GitHub Desktop.
But does it have a decimal?
has_decimal <- function(x){ (x - floor(x)) > 0 }
## from ?is.integer
is.wholenumber <-
function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) < tol
## from http://stackoverflow.com/questions/3476782/how-to-check-if-the-number-is-integer/3477158#3477158
## from SO and also twitter https://twitter.com/polesasunder/status/700091075269005313
is_whole <- function(x) x%%1==0
## apparently this is rather fast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment