[R] produce hours greater than 23
ggrothendieck at gmail.com
Thu Jan 5 02:14:28 CET 2006
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
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 at oreka.com <herodote at 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
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help