Re: [R] produce hours greater than 23

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 05 Jan 2006 - 12:14:28 EST

The chron package has a "times" class that represents times in days and fractions of a day. See the help desk article in R News 4/1 and the references therein for more info. Using "times" class the following one-line function, hms, will display produce the hours:mm:ss format:

library(chron)
hms <- function(x)

   sub("..:", ":", sprintf("%02.f%s", floor(24*x), format(x%%1)))

# test this by creating a vector 3 "times" objects

x <- structure(pi*seq(3), class = "times") hms(x) # "75:23:54" "150:47:47" "226:11:41"

On 1/4/06, herodote@oreka.com <herodote@oreka.com> wrote:
> Hy all,
>
> I wish to use the date function to draw againt the lifetime of a motor.
>
> This lifetime is given to me in Hours (it can go over 5000 hours)
>
> I'm unable to find how to convert this lifetime value to something like %H:%M:%S because when R see 24H it says 1 day, i don't want that, i just want %H:%M:%S with a value of %H higher than 24...
> for example:
> i've got this value in hours: 345.05 H
>
> I wish that R gives me : "345:3:0" or "345:03:00"
>
> What R function could do it?
>
> I've search for as.Date strptime... but none of these seems to be able to put a value for %H greater than 23.
>
> i've browse the help and docs and found nothing (am i blind?).
>
> thks all
> guillaume.
>
> ______________________________________________
> 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
>



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 Thu Jan 05 12:21:37 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:51 EST