[R] weird to me interaction between time() and %%, %/%

2010-08-31 Thread Alistair Gray
Dear List, I'm getting weird and unexpected behaviour using time and %%, or %/%. It's likely I'm not appreciating the nuances of floating point arithmetic. Or it could be a bug. I'm running R.version _ platform x86_64-redhat-linux-gnu kernel 2.6.33.8-149.fc13.x86_64

Re: [R] weird to me interaction between time() and %%, %/%

2010-08-31 Thread Steve Taylor
Yes it is a floating point problem. January 2005 is slightly less than 2005, although the gap is somewhat bigger than .Machine$double.eps time(junk) - 2005 # shows the gap is -2.2737e-13 for my machine Try something this: floor(time(junk) + 1e-10) — — — — — — — — —

Re: [R] weird to me interaction between time() and %%, %/%

2010-08-31 Thread Alistair Gray
Steve, thanks for the suggestion. Alistair On 01/09/10 11:20, Steve Taylor wrote: Yes it is a floating point problem. January 2005 is slightly less than 2005, although the gap is somewhat bigger than .Machine$double.eps time(junk) - 2005 # shows the gap is -2.2737e-13 for my machine Try

Re: [R] weird to me interaction between time() and %%, %/%

2010-08-31 Thread David Scott
Steve is undoubtedly right about this being a floating point problem. One comment I would make is that I think floor is a bit nicer for this, both conceptually and for readability. Also you don't need a really small value to add, half the sampling interval will work: junk - ts(1:125,

Re: [R] weird to me interaction between time() and %%, %/%

2010-08-31 Thread Gabor Grothendieck
On Tue, Aug 31, 2010 at 7:04 PM, Alistair Gray agg...@paradise.net.nz wrote: Dear List, I'm getting weird and unexpected behaviour using time and %%, or %/%. It's likely I'm not appreciating the nuances of floating point arithmetic. Or it could be a bug. Here are two workarounds to get the