[Rd] Bug in %in% (match)

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri Apr 4 22:09:32 MEST 2003


Nicholas Lewin-Koh <nikko at hailmail.net> writes:

> Hi,
> Am I hitting some limit in match? Consider the following example:
> 
> > tst<-seq(100,125,by=.2)%in%seq(0,800,by=.1)
> > sum(tst)
> [1] 76

> Gives the correct answer. Did I miss something?

The fact that 1/5 and 1/10 are not represented exactly in a binary
computer? 

> sum(tst<-seq(100,125,by=.2)%in%seq(0,800,by=.1))
[1] 76
> sum(tst<-seq(100,125,by=.2)%in%round(seq(0,800,by=.1),1))
[1] 126

And, just to be sure:

> sum(round(seq(100,125,by=.2),1)%in%round(seq(0,800,by=.1),1))
[1] 126


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907



More information about the R-devel mailing list