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). Bendix ---------------------- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 bxc at steno.dk www.biostat.ku.dk/~bxc
"BXC (Bendix Carstensen)" <bxc at steno.dk> writes:> 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).Ummm, how are you going to convert a number of days to years/months/days without specifying an origin? (00-01-00 could be 28,29,30, or 31 days.) Unless, of course you want to deal in "banker's months" of 30 + 5.25625/12 days. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
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)