[R] strange behaviour with equality after simple subtraction

From: martin sikora <martin.sikora_at_upf.edu>
Date: Fri 26 Jan 2007 - 16:05:01 GMT


hello,  

today while trying to extract data from a list for subsequent analysis, i stumbled upon this funny behavior on my system:  

> x<-c(0.1,0.9)

> 1-x[2]

[1] 0.1

> x[1]

[1] 0.1

> x[1]==1-x[2]

[1] FALSE
> x[1]>1-x[2]

[1] TRUE  
> x<-c(0.3,0.7)

> x[1]

[1] 0.3

> x[2]

[1] 0.7

> 1-x[2]

[1] 0.3

> x[1]==1-x[2]

[1] FALSE   but:  

> x<-c(0.4,0.6)

> x[1]

[1] 0.4

> x[2]

[1] 0.6

> 1-x[2]

[1] 0.4

> x[1]==1-x[2]

[1] TRUE   any ideas why this might be? in my data i have values that are calculated like above, e.g.  

y=x if x<=0.5, else y=1-x  

now because of that behaviour whenever i want to get values e.g. <0.1 from my data, i will also get all values of y=0.1 that came from the subtraction.  

i'm using R 2.4.0 on windows XP; this is my sessionInfo():  

> sessionInfo()

R version 2.4.0 (2006-10-03)

i386-pc-mingw32  

locale:

LC_COLLATE=Spanish_Spain.1252;LC_CTYPE=Spanish_Spain.1252;LC_MONETARY=Spanis h_Spain.1252;LC_NUMERIC=C;LC_TIME=Spanish_Spain.1252  

attached base packages:

[1] "methods"   "stats"     "graphics"  "grDevices" "utils"     "datasets"
"base"     

>
 

thanks a lot  

martin

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch 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. Received on Sat Jan 27 03:23:38 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 26 Jan 2007 - 17:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.