[R] Surprising behavior using seq()

Bert Gunter gunter.berton at gene.com
Fri Nov 12 20:02:43 CET 2010


Not weird at all!!! You need to understand how computers do
arithmetic. See R FAQ 7.31.
-- Bert

On Fri, Nov 12, 2010 at 10:55 AM, Vadim Patsalo <patsalov at gmail.com> wrote:
> Hello R-help,
>
> I noticed the following surprising behavior when using %in% to find elements in a vector generated using seq().
>
> # weird!!!
>> c(7.7, 7.8, 7.9) %in% seq(4, 8, by=0.1)
> [1]  TRUE FALSE  TRUE
>
> # OK now
>> c(7.7, 7.8, 7.9) %in% round(seq(4, 8, by=0.1), 1)
> [1] TRUE TRUE TRUE
>
> # wait, how is this different?
>> c(7.7, 7.8, 7.9) %in% seq(7, 8, by=0.1)
> [1] TRUE TRUE TRUE
>
> Is there an obvious reason for this behavior which I am missing? Seems like a bug to me...
>
> Thanks in advance!
> Vadim
>
>> sessionInfo()
> R version 2.12.0 (2010-10-15)
> Platform: i386-apple-darwin9.8.0/i386 (32-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] graphics  grDevices utils     datasets  stats     methods   base
>
> other attached packages:
> [1] cluster_1.13.1  nlme_3.1-97     lattice_0.19-13
>
> loaded via a namespace (and not attached):
> [1] grid_2.12.0
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Bert Gunter
Genentech Nonclinical Biostatistics



More information about the R-help mailing list