When durations are computed in data.table (v1.9.2), the wrong units can be printed with POSIXct arithmetic. It seems the first units are chosen.
require(\"da
Forcing units is the way to go until #761 is fixed. Here's another option:
dt[ , difftime(max(time), min(time), units = 'mins'), by = id]
# id V1
# 1: 1 40 mins
# 2: 2 80 mins
This allows you to retain the class
of the output (difftime
) if you'd like.
More than anything I find the behavior of R to fundamentally change the contents of the difftime
object based on the units
attribute quite strange. In other places in R, this conversion would simply be handled by the print
method while the stored value of the object remains consistent.