[R] Rounding error in seq(...)

Bert Gunter gunter.berton at gene.com
Wed Sep 30 21:01:12 CEST 2009


Inline Below.

Bert Gunter
Nonclinical Biostatistics
467-7374

http://devo.gene.com/groups/devo/depts/ncb/home.shtml

 

 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Michael Knudsen
Sent: Wednesday, September 30, 2009 11:50 AM
To: Duncan Murdoch
Cc: r help
Subject: Re: [R] Rounding error in seq(...)

On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch <murdoch at stats.uwo.ca>
wrote:

> Why?  You asked for an increment of 1 in the second case (which is exactly
> represented in R), then divided by 10, so you'll get the same as 0.3 gives
> you.  In the seq() case you asked for an increment of a number close to
but
> not equal to 1/10 (because 1/10 is not exactly representable in R), so you
> got something different.

Well, the problem is that I don't know how seq is implemented. I just
assumed that it wouldn't behave like this.

-- This represents common misconceptions about the nature of floating point
computations/finite precision arithmetic. See 7.31 in the R FAQ. You may
wish to Google/Wikipedia on "floating point computation" or something
similar for more info.

-- Bert




More information about the R-help mailing list