[R] bug in difftime with as.POSIXct

Dan Kelley Dan.Kelley at dal.ca
Sun Jan 27 20:12:39 CET 2008


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.



More information about the R-help mailing list