There is a [.difftime
version of the [
function but no [[.difftime
version of [[
> `[.difftime`
function (x, ..., drop = TRUE)
{
cl <- oldClass(x)
class(x) <- NULL
val <- NextMethod("[")
class(val) <- cl
attr(val, "units") <- attr(x, "units")
val
}
<bytecode: 0x1053916e0>
<environment: namespace:base>
So the for
function is pulling items from the y-object with [[
and it is loosing its attributes. This would let you get what you expected to see:
> for(i in seq_along(y) ){print(y[i])}
Time difference of 0.5 mins
Time difference of 1 mins
Time difference of 2 mins
> for(i in seq_along(y) ){print(class(y[i]))}
[1] "difftime"
[1] "difftime"
[1] "difftime"