0

I noticed recently a weird behavior when I wanted to differentiate a variable by the remainder.

x <- ifelse(48.002 %% 1 == 0.002, 1, 0)

However, testing the logic operation above showed this is not true.

48.002 %% 1 == 0.002
[1] FALSE

While if I use >= instead of ==, it could identify correctly:

48.002 %% 1 >= 0.002
[1] TRUE
 48.001 %% 1 >= 0.002
[1] FALSE

Could someone please help me understand why this is happening? Thanks.

NelsonGon
  • 12,469
  • 5
  • 25
  • 52
Xinting WANG
  • 1,725
  • 2
  • 13
  • 19

0 Answers0