Re: [R] "which" is wrong?

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Sun 27 Mar 2005 - 02:52:46 EST

Troels Ring wrote:

> Dear friends,
> R 2.0.1 on windows XP:
>
> TOT <- seq(0.01,1,by=0.01)
> which(TOT==0.06)
> # numeric(0)
> which(TOT>0.06)
> # [1] 6 7 8 etc
> which(TOT<0.06)
> #[1] 1 2 3 4 5
> TOT[6]
> #[1] 0.06
> TOT[6]==0.06
> #[1] FALSE
>
> but
> TOT[5]==0.05
> #[1] TRUE
> and
> which(TOT==0.05)
> # [1] 5
>
>
>
>
>
> TOT looks as expected when printed,
> 0.35 and 0.36 behaves similarly
>
> I have tried on another machine with the same result - wonder what
> happens and whether
> this is as expected ?

It is expected: the 0.06 *calculated* by seq() is computationally a little bit different than the 0.06 you have typed - we are working with floating point calculations on a digital computer. See ?all.equal for help.

Uwe Ligges

> Best wishes
> Troels Ring,
> Aalborg, Denmark
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Mar 27 02:55:44 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:56 EST