Very simple true numeric statement incorrectly evaluates to false

30 Views Asked by At

In R, I am evaluating a simple statement. It should return TRUE but it returns FALSE:

>a = c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5)
>b = seq(from=0, to=1.5,by = 0.1)
> a==b
 [1]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE FALSE
[16]  TRUE

> b[3]
[1] 0.2
> b[3] == 0.2
[1] TRUE #This is correct

> b[4]
[1] 0.3
> b[4] == 0.3
[1] FALSE #This is incorrect

Why is this TRUE statement evaluating to FALSE?

0

There are 0 best solutions below