[R] precision in seq
Eric Elguero
Eric.Elguero at mpl.ird.fr
Tue Feb 5 13:21:54 CET 2008
thank you to all who answered.
> 0+0.05+
+ 0.05+0.05+0.05+0.05+0.05+0.05+
+ 0.05+0.05+0.05+0.05+0.05+0.05+
+ 0.05+0.05+0.05+0.05+0.05+0.05 - 0.95
[1] 3.330669e-16
> seq(0,1,0.05)[20] - 0.95
[1] 1.110223e-16
> 0+19*0.05 - 0.95
[1] 1.110223e-16
so this is the way seq calculates. I would have guessed
that addition was more accurate than multiplication,
but that is not the case.
this one however bothers me:
> 19/20-0.95
[1] 0
I noticed this problem when I tried to extract rows of a matrix
according to whether values of some vector where in the set
(0,0.05,...,0.95,1), with something like x%in%seq(0,1,0.05)
Now I understand that I should not use this construction
unless x is of type integer. Would you agree?
Eric Elguero
More information about the R-help
mailing list