[R] Problem with <= (less than or equal): not giving the expected result
Johannes.Rainer at eurac.edu
Tue Apr 5 13:34:27 CEST 2016
I have the following problem:
I have a function in which I check if the difference between values is smaller or equal to a certain threshold. I however realized that I might get there some unexpected results:
> abs(1 - 0.95) >= 0.05
## So that’s fine, but:
> abs(1 - 0.95) <= 0.05
Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite disturbing.
Along these lines:
> abs(0.95 - 1) > 0.05
> abs(0.95 - 1) < 0.05
I guess that has to do with the floating point representation of the data?
Is there something I miss or is there any solution to this?
Thanks for any help!
I tried this on different R-version (including 3.2.3 and 3.3.0 alpha); The R-version I used for the code above is:
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)
 LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
 LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
 LC_PAPER=en_US.UTF-8 LC_NAME=C
 LC_ADDRESS=C LC_TELEPHONE=C
 LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
 stats graphics grDevices utils datasets methods base
More information about the R-help