[R] print format for difftime

Gabor Grothendieck ggrothendieck at gmail.com
Sat May 21 14:35:08 CEST 2005


On 5/21/05, BXC (Bendix Carstensen) <bxc at steno.dk> wrote:
> Has anyone written a function that will print a difftime in the form:
> 
> hh:mm:ss
> 
> or
> 
> yy-mm-dd hh:mm:ss
> 
> depending on the actual size.
> (sloppy notation for months/minutes, but surely you get the point).
> 

Assuming your difftime, dd, represents time since the Epoch,
convert it to units of days, dd.day, and then use chron or times
depending on whether or not its one day or more.

library(chron)
zero <- structure(0, units = "secs", class = "difftime")
dd.day <- as.vector((dd + zero)/(24*60*60))
if (dd.day < 1) times(dd.day) else chron(dd.day)




More information about the R-help mailing list