[R] %in% not working

Neil Klepeis nklepeis at uclink4.berkeley.edu
Sat Nov 2 02:38:35 CET 2002

Thanks to Thomas and everyone on my floating point confusion,

Is there any reason why conversion to 'character' wouldn't be the safest 
way to compare decimal numbers:

 > 1.253 %in% seq(1.1,1.3,by=0.001)
 > 1.253 %in% as.character(seq(1.1,1.3,by=0.001))
[1] TRUE
 > 0.001 %in% 1E-3
[1] TRUE
 > "0.001" %in% "1E-3"
 > as.character(0.001) %in% as.character(1E-3)
[1] TRUE

If so, could R do something like this automatically?

Thomas Lumley wrote:
> The optimistic version of Peter's general principle is that two real
> numbers will compare equal only if they were obtained by the same
> computation.

Neil E. Klepeis, UC Berkeley, School of Public Health,
and Lawrence Berkeley National Laboratory,
Berkeley, CA USA.  Voice: 831-768-9510

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list