Hi Everyone,
as part of a larger script, I need to insert the result of a simple minus
operation into an if statement.
I have noticed that the precision that appear on the screen is not the
precision
in which R stores the result of the minus operation, and that this change
alters
the result of the if statement. For example, when running this simple script:
> a=0.90
> b=0.95
> c=b-a
> e=paste(c)
> if(c==0.05) d=12
I get:
> c
[1] 0.05
> d
Error: object 'd' not found
> e
[1] "0.0499999999999999"
Although I have solved it by changing the command for c to:
> c=round((b-a),15)
I do not understand the source of this mistake and how it can be avoided in the
future
Many thanks and sorry for this very basic question...
Yoni Gavish
Department of Life Sciences,
Ben-Gurion University of the Negev,
POB 653, Beer Sheva, 84105
ISRAEL
Tel: 972-77-6450238 (home), 972-50-9930553 (mobile)
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
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.