[R] difftime result for days not an integer?

Thomas Lumley tlumley at u.washington.edu
Thu Feb 11 21:53:41 CET 2010


On Thu, 11 Feb 2010, Jonathan wrote:

> Anybody have an idea why I would get a non-integer value for the
> number of days here?
>
>> difftime('2004-08-05','2001-01-03',units='days')
> Time difference of 1309.958 days

Because it's not a whole number of 24-hour periods, due to daylight saving time: 0.958 is 23/24.

>
> Would you just round off?
>

Yes, or use as.Date() if you only want to consider whole days

R> as.Date('2004-08-05')-as.Date('2001-01-03')
Time difference of 1310 days

        -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle



More information about the R-help mailing list