Re: [R] produce hours greater than 23

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

In thinking about this some more here is an even shorter version of hms. Note that %02.f produces at least 2 digits using leading zeros to fill in if necessary and %5.5s truncates the string to the first 5 characters (since our string is of the form mm:ss:hh and we only need the mm:ss part).

hms2 <- function(x) sprintf("%02.f:%5.5s", floor(24*x), format(x%%1, "m:s:h"))

On 1/4/06, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> 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:29:28 2006

This archive was generated by hypermail 2.1.8 : Thu 05 Jan 2006 - 16:49:06 EST