Are there limitations to seq
? I can not explain this:
x=seq(from=.008, to=.015, by=.001)
x
[1] 0.008 0.009 0.010 0.011 0.012 0.013 0.014 0.015
x[2]
[1] 0.009
x[x==0.009]
numeric(0)
x[x==.01]
[1] 0.01
What is the exact value of x[2]
?
To my surprise:
(.008+.001)==.009
[1] FALSE
(.08+.01)==.09
[1] TRUE
How does R sum 0.008+.001
and what is the exact value?
As @joran pointed out, the question has already been answered.
In this case, the easiest solution is
x[round(x,3)==.009]
[1] 0.009
round(.008+.001,3)==.009
[1] TRUE