[R] weird "max" behavior for difftime class

Jacob Wegelin jawegelin at ucdavis.edu
Tue Apr 4 00:03:55 CEST 2006

If you apply the "max" function to a vector of class "difftime" with
units="days", the returned value is in units of "seconds".

Is this not a bug?  At any rate it can lead to confusing results if one
buries a call to "max" deep in some data analysis code.


> y<-structure(1, class = "difftime", units = "days")
> max(y)
Time difference of 86400 secs
> y
Time difference of 1 days
> min(y)
Time difference of 86400 secs
> as.numeric(min(y))
[1] 86400
> dput(min(y))
structure(86400, units = "secs", class = "difftime")

> methods("max")
no methods were found
> methods("difftime")
no methods were found
Warning message:
function 'difftime' appears not to be generic in: methods("difftime")

Thanks for any insights

Jake Wegelin

More information about the R-help mailing list