Re: [R] print format for difftime

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 21 May 2005 - 22:35:08 EST

On 5/21/05, BXC (Bendix Carstensen) <bxc@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)



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat May 21 22:39:44 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:59 EST