0
> startPoll
[1] 15.6
> endPoll
[1] 16.1
> threshold
[1] 0.5
> abs(startPoll - endPoll)
[1] 0.5
> abs(startPoll - endPoll) > threshold 
[1] TRUE
> 0.5 > 0.5
[1] FALSE

Why is it that I am getting True for 0.5 > 0.5 when I am using

abs(startPoll - endPoll) > threshold

but when I use

0.5 > 0.5

I get the expected FALSE?

Jibril
  • 967
  • 2
  • 11
  • 29
  • 1
    I'm guessing the linked question covers it. Let me know if not – Frank Apr 26 '16 at 15:02
  • `options(digits = 20); abs(startPoll - endPoll); threshold` – nrussell Apr 26 '16 at 15:03
  • @Frank Well, I certainly understand WHY it does it now, but I do not understand how to go about fixing it. It says you can use an all-equal's function, but I am not checking if they are equal here. I am looking for one greater than the other. In MOST of the cases of my code, they won't be this close, but these close cases are just as important. – Jibril Apr 26 '16 at 15:14
  • You can add a fudge factor / tolerance so that near equality goes the way you want it to: `x > y | all.equal(x, y, tol = 1e-3)`. Or, if your numbers really do have only one digit after the decimal point, multiply by 10 and use integers instead. – Frank Apr 26 '16 at 15:22
  • You could use something like: `abs(15.6 - 16.1) > 0.5 - sqrt(.Machine$double.eps)`. This is the default tolerance used by `all.equal`. – Anders Ellern Bilgrau Apr 26 '16 at 15:24

0 Answers0