Possible Duplicate:
Numeric comparison difficulty in R
Hello All,
According to "R Inferno" paper. I'm right now in the first circle of R hell. This is where pagans expect 0.1 == 0.3/3. Paper recommends using all.equal
function for such cases, however I need to check ">=" or "<=" conditions. With current example on of them fail:
> .1 >= .3/3
[1] TRUE
> .1 <= .3/3
[1] FALSE
Is there a similar function to all.equal that checks inequalities?
Thank you,
Ilya
Please see the R FAQ entry Why doesn't R think these numbers are equal and the references therein.
You could try judicious use of
zapsmall()
which seems to give the behavior you are looking for. I don't know if this works in all situations. e.g.,See these questions:
Generally speaking, you can deal with this by including a tolerance level as per the second link above.
The main test of
all.equal
is whetherabs(x-y) < tolerance
for some valuesx
andy
and some smalltolerance
. Equivalent inequality tests would check: