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

Jason Turner jasont at indigoindustrial.co.nz
Wed Oct 8 19:45:49 CEST 2003


Achim Zeileis wrote:

> On Wednesday 08 October 2003 11:27, Thomas Bock wrote:
...
>>I can not understand why the expression in
>>
>>the subject does not work correct:
>> > dcrn[which(fn == inve[2])]
>>
>>numeric(0)
>>
>> > inve[2]
>>
>>[1] 406.7
>>
...
>   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...

I usually specify...

tol <- sqrt(.Machine$double.eps)
dcrn[(fn - inve[2]) < tol]

See ?.Machine for details.

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
http://www.indigoindustrial.co.nz
64-21-343-545
jasont at indigoindustrial.co.nz




More information about the R-help mailing list