Possible Duplicate:
Why are these numbers not equal?
Can anyone explain to me, why R answers FALSE
in the following case?
(1-0.9)>=0.1
How can I get TRUE
for comparisons of that kind?
Possible Duplicate:
Why are these numbers not equal?
Can anyone explain to me, why R answers FALSE
in the following case?
(1-0.9)>=0.1
How can I get TRUE
for comparisons of that kind?
This is the classic R FAQ 7.31. You need all.equal
This has to do with floating point precision. There is in essence an infinite amount of floating points, do representing them in the computer can only be done discretely, and thus with limited precision. To take this limited precision into account, use all.equal
to make the comparison. As @RomainFracois said, this is very frequently asked question in R.
You could create your own binary operators to do what you're after and store them in your .Rprofile:
`%>=%` <- function(x, y) all.equal(x, y) | x > y
`%<=%` <- function(x, y) all.equal(x, y) | x < y
c(1-.9)>=.1
c(1-.9)%>=% .1