[R] Logical inconsistency

Bernardo Rangel Tura tura at centroin.com.br
Thu Dec 11 23:10:10 CET 2008


On Thu, 2008-12-11 at 17:23 +0200, Kenn Konstabel wrote:
> Hi,
> 
> I agree -- and my examples using round were meant as bad and dangerous
> examples. Using round at the last step is better and may solve the problem,
> but in your example ...
> 
> > round(8.8-7.8,1)==1
> [1] TRUE
> 
> ... you have to know in advance how many decimal places can possibly make a
> difference (is it just one? maybe it is 2? 3? 15?).
> 
> > round(8.8-7.8,14)==1
> [1] TRUE
> > round(8.8-7.8,15)==1
> [1] FALSE
> 
> ... or, equivalently,
> 
> > 8.8-7.8-1 < 1e-15
> [1] TRUE
> > 8.8-7.8-1 < 1e-16
> [1] FALSE
> 
> Best regards,
> Kenn

Hi Kenn,

If you know "guard digits" approach you know the answer for your
question.

You need the minimum numbers of significant digits and put all numbers
in same number of significant digits for comparison.

In all example put in this thread we need only 1 decimal place so you
round for 1 decimal place, if for your job you need 3 decimal places
precision you round for 3 decimal place.


I think don't make sense you using 10 decimal place precision if your
problem need 2 decimal places precision ...

-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil



More information about the R-help mailing list