[R] Problem with <= (less than or equal): not giving the expected result

Thierry Onkelinx thierry.onkelinx at inbo.be
Tue Apr 5 14:30:31 CEST 2016


FAQ 7.31

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2016-04-05 13:34 GMT+02:00 Rainer Johannes <Johannes.Rainer op eurac.edu>:

> Dear All,
>
> 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
> [1] TRUE
> ## So that’s fine, but:
> > abs(1 - 0.95) <= 0.05
> [1] FALSE
>
> 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
> [1] TRUE
> > abs(0.95 - 1) < 0.05
> [1] FALSE
>
> 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!
>
> cheers, jo
>
>
>
> 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:
>
> > sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> ______________________________________________
> R-help op r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list