Re: [R] %in% not working

About this list Date view Thread view Subject view Author view Attachment view

From: Neil Klepeis (nklepeis@uclink4.berkeley.edu)
Date: Sat 02 Nov 2002 - 12:38:35 EST


Message-id: <3DC32C9B.9020006@uclink4.berkeley.edu>

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] FALSE
> 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"
[1] FALSE
> 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
ed

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jun 2004 - 09:31:35 EST