When I extend a vector of difftimes by another difftime object, then it seems that the unit of the added item is ignored and overridden without conversion:
> t = Sys.time()
> d = difftime(c((t+1), (t+61)), t)
> d
Time differences in secs
[1] 1 61
> difftime(t+61, t)
Time difference of 1.016667 mins
> d[3] = difftime(t+61, t)
> d
Time differences in secs
[1] 1.000000 61.000000 1.016667
> as.numeric(d)
[1] 1.000000 61.000000 1.016667
This is in R 3.1.0. Is there a reasonable explanation for this behavior? I just wanted to store some time differences in this way for later use and didn't expect this at all. I didn't find this documented anywhere..
Okay, for now I'm just helping myself with always specifying the unit:
> d[3] = difftime(t+61, t, unit="secs")
> d
Time differences in secs
[1] 1 61 61
From
help("difftime")
units = "auto"
is the default. So for a difference of 1 and 61 seconds, if you were to choose minutes,One of those is less than one, so by default since you did not specify the units R chose them for you according to the guidelines above. Additionally, the units are saved with the object
But you can change the units with
units<-