Skip to content
Prev 144995 / 398500 Next

Converting a 'difftime' to integer - How to???

Martin Hvidberg wrote:
The canonical way is

 > as.numeric(d, units="days")
[1] 72

In fact, you can leave out the units when dealing with differences 
between Date objects, because it is always "days", but that is an 
undocumented implementation detail.

If you have differences between POSIXt objects, real confusion can arise:

 > ISOdatetime(2008,1,1,12,0,2) - ISOdatetime(2008,1,1,12,0,0)
Time difference of 2 secs
 > ISOdatetime(2008,1,1,12,2,0) - ISOdatetime(2008,1,1,12,0,0)
Time difference of 2 mins
 > ISOdatetime(2008,1,1,14,0,0) - ISOdatetime(2008,1,1,12,0,0)
Time difference of 2 hours