[R] Surprising behavior using seq()

Vadim Patsalo patsalov at gmail.com
Mon Nov 15 15:24:55 CET 2010


Patrick and Bert,

Thank you both for you replies to my question. I see how my naïve expectations fail to floating point arithmetic. However, I still believe there is an underlying problem.

It seems to me that when asked,

> c(7.7, 7.8, 7.9) %in% seq(4, 8, by=0.1)
> [1]  TRUE FALSE  TRUE

R should return TRUE in all instances. %in% is testing set membership... in that way, shouldn't it be using all.equal() (instead of the implicit '=='), as Patrick suggests the R inferno?

Is there a convenient way to test set membership using all.equal()? In particular, can you do it (conveniently) when the lengths of the numeric lists are different?

Thanks again for your reply!
Vadim

On Nov 13, 2010, at 5:46 AM, Patrick Burns wrote:

> See Circle 1 of 'The R Inferno'.



More information about the R-help mailing list