Re: [R] precision in seq

From: Eric Elguero <>
Date: Tue, 5 Feb 2008 13:21:54 +0100

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 mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 05 Feb 2008 - 12:27:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Feb 2008 - 21:30:11 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive