Assuming I want test if 'a' is less or equal than 'b' when both are floats. I would go with
isTRUE(all.equal(a,b)) || a <= b
I'm wondering if there's a better way than this. Is there a function like all.equal for less or equal ( / greater than equal ) that allows "near equality"?
And what should one do if instead of single numbers one wants to compare two vectors of floats?
Update: @shadow pointed to me Numeric comparison difficulty in R
One could of course set tolerance explicitly and avoid all.equal:
tol = 1e-5
# a equals b
abs(a-b) <= tol
# a less or equal to b
a <= b + tol
Here is some discussion about absolute vs. relative tolerance: http://realtimecollisiondetection.net/blog/?p=89
I guess as always, there's no 'right' way to implement this.