This is FAQ 7.31:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium
Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be
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
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] Namens yoni gavish
> Verzonden: donderdag 29 juli 2010 8:23
> Aan: r-help at r-project.org
> Onderwerp: [R] precision of minus operation and if statments
>
> 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]]
>
>
Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in this message
and any annex are purely those of the writer and may not be regarded as stating
an official position of INBO, as long as the message is not confirmed by a duly
signed document.