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

2009-10-25 Thread David Airey
>> can you explain that a little more detailed? >> Perhaps I miss the background knowledge - but it seems just absurd to me. >> >> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? >> >> why is >> x <- 0.1 + 0.1 +0.1 >> not equal to >> y <- 0.3 > > Remember that this is in BINARY a

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

2009-09-30 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: Peter Dalgaard [mailto:p.dalga...@biostat.ku.dk] > Sent: Wednesday, September 30, 2009 3:58 PM > To: Nordlund, Dan (DSHS/RDA) > Cc: Douglas Bates; r help > Subject: Re: [R] Rounding error in seq(...) > <<>> > > > &g

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

2009-09-30 Thread Peter Dalgaard
Nordlund, Dan (DSHS/RDA) wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Douglas Bates Sent: Wednesday, September 30, 2009 3:06 PM To: Peter Dalgaard Cc: r help; Duncan Murdoch Subject: Re: [R] Rounding error in seq(...) On

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

2009-09-30 Thread Erik Iverson
> In an earlier thread on this theme I believe that someone quoted Brian > Kernighan as saying "10 times 0.1 is hardly ever 1" but I haven't been > able to track down the quote. Can anyone point us to such a quote? > It summarizes the situation succinctly, See FAQ 7.31 :) ___

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

2009-09-30 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Douglas Bates > Sent: Wednesday, September 30, 2009 3:06 PM > To: Peter Dalgaard > Cc: r help; Duncan Murdoch > Subject: Re: [R] Rounding error in seq(...

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

2009-09-30 Thread David Winsemius
On Sep 30, 2009, at 6:05 PM, Douglas Bates wrote: On Wed, Sep 30, 2009 at 2:32 PM, Peter Dalgaard> wrote: Martin Batholdy wrote: hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no ro

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

2009-09-30 Thread Douglas Bates
On Wed, Sep 30, 2009 at 2:32 PM, Peter Dalgaard wrote: > Martin Batholdy wrote: >> >> hum, >> >> can you explain that a little more detailed? >> Perhaps I miss the background knowledge - but it seems just absurd to me. >> >> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? >> >> why is

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

2009-09-30 Thread Ted Harding
On 30-Sep-09 19:32:46, Peter Dalgaard wrote: > Martin Batholdy wrote: >> hum, >> >> can you explain that a little more detailed? >> Perhaps I miss the background knowledge - but it seems just absurd to >> me. >> >> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? >> >> why is >> x <

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

2009-09-30 Thread Duncan Murdoch
On 9/30/2009 3:59 PM, Ista Zahn wrote: For my own edification more than anything (I never took computer science): is a = seq(0.1,0.9,by=0.1) a <- as.character(a) a[3] == "0.3" [1] TRUE safe? No. Someone might be in a locale where the comma is used as the decimal separator. Take a look at

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

2009-09-30 Thread Ista Zahn
For my own edification more than anything (I never took computer science): is > a = seq(0.1,0.9,by=0.1) > a <- as.character(a) > a[3] == "0.3" [1] TRUE safe? -Ista On Wed, Sep 30, 2009 at 3:46 PM, cls59 wrote: > > > Martin Batholdy wrote: >> >> hum, >> >> can you explain that a little more det

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

2009-09-30 Thread cls59
Martin Batholdy wrote: > > hum, > > can you explain that a little more detailed? > Perhaps I miss the background knowledge - but it seems just absurd to > me. > > 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? > > Unfortunately this comes as an utter shock to many people wh

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

2009-09-30 Thread Gabor Grothendieck
See: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f On Wed, Sep 30, 2009 at 2:40 PM, Michael Knudsen wrote: > Hi, > > Today I was flabbergasted to see something that looks like a rounding > error in the very basic seq function in R. > >> a = seq

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

2009-09-30 Thread Greg Snow
r-help-boun...@r- > project.org] On Behalf Of Martin Batholdy > Sent: Wednesday, September 30, 2009 1:18 PM > To: Duncan Murdoch > Cc: r help > Subject: Re: [R] Rounding error in seq(...) > > hum, > > can you explain that a little more detailed? > Perhaps I miss the back

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

2009-09-30 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Batholdy > Sent: Wednesday, September 30, 2009 12:18 PM > To: Duncan Murdoch > Cc: r help > Subject: Re: [R] Rounding error in seq(...) > >

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

2009-09-30 Thread Peter Dalgaard
Martin Batholdy wrote: hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? why is x <- 0.1 + 0.1 +0.1 not equal to y <- 0.3 Remember that this is in BINARY ar

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

2009-09-30 Thread Rolf Turner
On 1/10/2009, at 8:17 AM, Martin Batholdy wrote: hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? why is x <- 0.1 + 0.1 +0.1 not equal to y <- 0.3 ? You

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

2009-09-30 Thread Duncan Murdoch
On 9/30/2009 3:17 PM, Martin Batholdy wrote: hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? R uses a binary floating point storage format, which is the

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

2009-09-30 Thread Michael Knudsen
On Wed, Sep 30, 2009 at 8:40 PM, Michael Knudsen wrote: >> a = seq(0.1,0.9,by=0.1) >> a > [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 >> a[1] == 0.1 > [1] TRUE >> a[2] == 0.2 > [1] TRUE >> a[3] == 0.3 > [1] FALSE A friend of mine just pointed out a possible solution: > a=seq(0.1,0.9,by=0.1) > a = s

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

2009-09-30 Thread Martin Batholdy
hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? why is x <- 0.1 + 0.1 +0.1 not equal to y <- 0.3 ? Am 30.09.2009 um 21:04 schrieb Duncan Murdoch: On

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

2009-09-30 Thread Duncan Murdoch
On 9/30/2009 2:50 PM, Michael Knudsen wrote: On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch 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 inc

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

2009-09-30 Thread Bert Gunter
To: Duncan Murdoch Cc: r help Subject: Re: [R] Rounding error in seq(...) On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch 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 >

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

2009-09-30 Thread Michael Knudsen
On Wed, Sep 30, 2009 at 8:44 PM, Duncan Murdoch 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 equa

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

2009-09-30 Thread Duncan Murdoch
On 9/30/2009 2:40 PM, Michael Knudsen wrote: Hi, Today I was flabbergasted to see something that looks like a rounding error in the very basic seq function in R. a = seq(0.1,0.9,by=0.1) a [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 a[1] == 0.1 [1] TRUE a[2] == 0.2 [1] TRUE a[3] == 0.3 [1] F

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

2009-09-30 Thread Michael Knudsen
Hi, Today I was flabbergasted to see something that looks like a rounding error in the very basic seq function in R. > a = seq(0.1,0.9,by=0.1) > a [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 > a[1] == 0.1 [1] TRUE > a[2] == 0.2 [1] TRUE > a[3] == 0.3 [1] FALSE It turns out that the alternative > a