[R] bug in difftime with as.POSIXct

From: Dan Kelley <Dan.Kelley_at_dal.ca>
Date: Sun, 27 Jan 2008 11:12:39 -0800 (PST)

I am trying to do ephemeris calculations in R, which involves calculating an elapsed time. As illustrated below, difftime seems to have problems with my method, since the fractional day is sometimes the correct 0.5 and sometimes the incorrect 0.46.

I am doing this on with R-2.6.1 on a powerpc-apple-darwin8.10.1 system.

I get the same results for as.POSIXlt() instead of as.POSIXct(), but the problem goes away if I use ISOdatetime for the first date in the difference.

Since I have a workaround, I am mainly posting this as a bug report, and also as a cautionary note, in case other folks search the forum for similar issues.

> difftime(as.POSIXct("1975-04-26"),ISOdatetime(1899,12,31,12,0,0),units="days")
Time difference of 27508.5 days
> difftime(as.POSIXct("1975-04-27"),ISOdatetime(1899,12,31,12,0,0),units="days")
Time difference of 27509.5 days
> difftime(as.POSIXct("1975-04-28"),ISOdatetime(1899,12,31,12,0,0),units="days")
Time difference of 27510.46 days
> difftime(as.POSIXct("1975-04-29"),ISOdatetime(1899,12,31,12,0,0),units="days")
Time difference of 27511.46 days

-- 
View this message in context: http://www.nabble.com/bug-in-difftime-with-as.POSIXct-tp15122749p15122749.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org 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 Sun 27 Jan 2008 - 19:15:07 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 Sun 27 Jan 2008 - 20:30:08 GMT.

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

list of date sections of archive