[R] Something weird

Marc Schwartz marc_schwartz at me.com
Fri Jun 3 13:17:14 CEST 2016


> On Jun 3, 2016, at 6:03 AM, Juan Andres Hernandez <jhernandezcabrera at gmail.com> wrote:
> 
> Can anybody explain me this weird result?
> a=3
> as.integer(a)
> 1] 3
> 
> a=(3/10)/0.1
> a
> [1] 3
> 
> as.integer(a)
> [1] 2
> 
> Thank's in advance
> 
> Juan A Hernández


See:

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

Also, note that as per the Value section of ?as.integer:

  "Non-integral numeric values are truncated towards zero..."

> print((3/10) / 0.1, 20)
[1] 2.9999999999999995559

> (3/10) / 0.1 == 3
[1] FALSE


Regards,

Marc Schwartz



More information about the R-help mailing list