[R] erratic behavior of match()?

Bernhard Klingenberg Bernhard.Klingenberg at williams.edu
Thu Apr 19 03:02:15 CEST 2007


Consider the code:

x <- seq(0,1,0.2)
y <- seq(0,1,0.01)
cbind(match(y,x),y)

which, surprisingly, doesn't show a match at 0.6! (It gives correct 
matches at 0, 0.2, 0.4, 0.8 and 1, though)

In addition,

x[4]==y[61]

yields FALSE. (but x[5]==y[81], the one for 0.8,  yields TRUE)

Is this a consequence of machine error or something else?
Could this be overcome? (It works correctly when integers are used in 
the sequences as well as in many other circumstances)

Thank you,

Bernhard



More information about the R-help mailing list