Skip to content
Prev 38380 / 398500 Next

Why does a[which(b == c[d])] not work?

On Wednesday 08 October 2003 11:27, Thomas Bock wrote:

            
The reason is that you shouldn't compare numeric output like that, 
consider the following example:

R> x <- 406.7 + 1e-5 
R> x
[1] 406.7
R> x == 406.7
[1] FALSE

whereas

R> x <- 406.7 + 1e-20 
R> x
[1] 406.7
R> x == 406.7
[1] TRUE

that is
  1.) `==' comparisons have a certain tolerance
  2.) the print output is not necessarily "precisely" your number

Instead of using `==' you should use a comparison with a certain 
tolerance you can specify...

hth,
Z