Re: [R] seq unexpected behavior

From: Marc Schwartz <MSchwartz_at_mn.rr.com>
Date: Thu 27 Jul 2006 - 11:47:44 EST

On Wed, 2006-07-26 at 18:35 -0700, Vries, Han de wrote:
> seq(0.1, 0.9 - 0.8, by = 0.1) gives the following error message:
>
> Error in seq.default(0.1, 0.9 - 0.8, by = 0.1) :
> wrong sign in 'by' argument
>
> but seq(0.1, 0.8 - 0.7, by = 0.1) gives
> [1] 0.1
> (no error message)
>
> Why do I get an error message in the first case?
> Han

See R FAQ 7.31 Why doesn't R think these numbers are equal?

> print(0.9 - 0.8, 20)

[1] 0.09999999999999997780

> print(0.8 - 0.7, 20)

[1] 0.10000000000000008882

In the first case, the result of the subtraction is slightly less than 0.1, resulting in a negative interval. In the second case, it is slightly greater than 0.1, which is OK.

HTH, Marc Schwartz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu Jul 27 11:50:50 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 27 Jul 2006 - 12:17:58 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.