Possible duplicate:Numerical comparison error in R
Hello everybody,
According to "R Inferno" . I'm in the first round of R hell. This is where pagans expect 0.1 == 0.3 / 3. The document recommends using the function all.equalfor such cases, however I need to check the conditions "> =" or "<=". In the current example, their failure:
all.equal
> .1 >= .3/3 [1] TRUE > .1 <= .3/3 [1] FALSE
Is there a similar function for all.equal that checks for inequalities?
Thank,
Ilya
See the following questions:
Generally speaking, you can handle this by including the tolerance level according to the second link above.
all.equal abs(x-y) < tolerance x y tolerance. :
abs(x-y) < tolerance
x
y
tolerance
x <= y: x-y < tolerance x < y: x-y < -tolerance x >= y: x-y > -tolerance x > y: x-y > tolerance
Please see the R FAQ. Why R does not consider these numbers equal and references to them.
You can try smart use zapsmall()that seems to give the behavior you are looking for. I do not know if this works in all situations. eg.
zapsmall()
.1 >= zapsmall(.3/3) [1] TRUE > .1 <= zapsmall(.3/3) [1] TRUE