[R] odd behavior of seq()

Marc Schwartz marc_schwartz at me.com
Thu Jul 3 20:37:06 CEST 2014


On Jul 3, 2014, at 1:28 PM, Matthew Keller <mckellercran at gmail.com> wrote:

> Hi all,
> 
> A bit stumped here.
> 
> z <- seq(.05,.85,by=.1)
> z==.05     #good
> [1]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> 
> z==.15  #huh????
> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> 
> More generally:
>> sum(z==.25)
> [1] 1
>> sum(z==.35)
> [1] 0
>> sum(z==.45)
> [1] 1
>> sum(z==.55)
> [1] 1
>> sum(z==.65)
> [1] 0
>> sum(z==.75)
> [1] 0
>> sum(z==.85)
> [1] 1
> 
> Does anyone have any ideas what is going on here?


See the MFAQ[1]:

  http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

Regards,

Marc Schwartz

[1] Most Frequently Asked Question



More information about the R-help mailing list