[R] Surprising behavior using seq()

P Ehlers ehlers at ucalgary.ca
Mon Nov 15 15:50:52 CET 2010


Vadim Patsalo wrote:
> 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?
> 
This looks like a job for zapsmall; check ?zapsmall.

   -Peter Ehlers

> Thanks again for your reply!
> Vadim
> 
> On Nov 13, 2010, at 5:46 AM, Patrick Burns wrote:
> 
>> See Circle 1 of 'The R Inferno'.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list