[R] problem with comparisons for vectors

Wu Gong wg2f at mtmail.mtsu.edu
Mon Jul 12 06:02:06 CEST 2010


I don't know the real reason, but help("==") gives some clues. 

For numerical and complex values, remember == and != do not allow for the
finite representation of fractions, nor for rounding error. Using all.equal
with identical is almost always preferable. See the examples. 

x1 <- 0.5 - 0.3
x2 <- 0.3 - 0.1
x1 == x2                           # FALSE on most machines
identical(all.equal(x1, x2), TRUE) # TRUE everywhere


-----
A R learner.
-- 
View this message in context: http://r.789695.n4.nabble.com/problem-with-comparisons-for-vectors-tp2285557p2285685.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list