[R] The elegant way to test if a number is a whole number
Alexander Engelhardt
alex at chaotic-neutral.de
Thu Sep 8 20:27:14 CEST 2011
Hi,
x <- 0.2*5
is.integer(x)
gives me FALSE because R stores it as a float number, right?
Is there an elegant way to work around that problem? Right now
I'm using
x <- 0.2*5
round(x) == x
which returns TRUE. But more strictly I should use all.equal(),
right?
I somehow just don't like the--pardon--ugliness of those pieces
of code. Maybe there is a beautiful way to write that. If not,
no big problem -- I just like beautiful code :-)
Cheers,
Alex
More information about the R-help
mailing list