[R] Logical inconsistency

Bernardo Rangel Tura tura at centroin.com.br
Thu Dec 11 03:16:26 CET 2008


On Tue, 2008-12-09 at 06:02 -0800, emma jane wrote:
> Many thanks for your help, perhaps I should have set my query in context .... !
> 
> I'm simply calculating an indicator variable [0,1] based on the whether the difference between two measured variables is > 1 or <=1.
> 
> I understand the FAQ about floating point arithmetic, but am still puzzled that it only apparently applies to certain elements, as follows:
> 
> 8.8 - 7.8 > 1
> > TRUE
> 
> 8.3 - 7.3 > 1
> > TRUE
>  
> However,
>  
> 10.2 - 9.2 > 1
> >FALSE
>  
> 11.3 - 10.3>1
> > FALSE
> 
> Emma Jane

Emma,

This solve two forms:

1-  use all.equal
> all.equal((10.2 - 9.2),1)
[1] TRUE

2- use round
> round(10.2 - 9.2,0)>1
[1] FALSE
> round(10.2 - 9.2,0)>=1
[1] TRUE




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



More information about the R-help mailing list