[R] what don't I get about numeric/double comparisons in R way?

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Dec 31 11:37:02 CET 2009


Peter Ehlers wrote:

>> actual_mean <- mean( range)
>> actual_sd <- sd( range)
>> expected_mean <- 218.213483146067
>> expected_sd <- 159.277118043936
>>
...
> Your code is not reproducible, but it seems fairly clear
> that you haven't yet read the help pages for identical()
> and all.equal(); or, if you have, you haven't done so
> very carefully. For ?identical, you'll find this:
...

Shorter version: "Do not rely on exact equality in floating-point 
arithmetic."

Instead use something like abs(actual_mean - expected_mean) < tol.

-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list