If you want the hours from a POSIXct, here is one way of doing it; you can
create a function for doing it:

> x <- Sys.time()
> x
[1] "2009-05-20 12:17:13 EDT"
> y <- difftime(x, trunc(x, units='days'), units='hours')
> y
Time difference of 12.28697 hours
> as.numeric(y)
[1] 12.28697
>
It depends on what type of computations you want to do with it.  You can
leave it as POSIXct and carry out a lot of them.  Can you specify what you
want?


On Wed, May 20, 2009 at 10:57 AM, Stavros Macrakis <macra...@alum.mit.edu>wrote:

> What is the recommended class for time of day (independent of calendar
> date)?
>
> And what is the recommended way to get the time of day from a POSIXct
> object? (Not a string representation, but a computable representation.)
>
> I have looked in the man page for DateTimeClasses, in the Time Series
> Analysis Task View and in Spector's Data Manipulation book but haven't
> found
> these. Clearly I can create my own Time class and hack around with the
> internal representation of POSIXct, e.g.
>
>    days <- unclass(d)/(24*3600)
>    days-floor(days)
>
> and write print.Time, `-.Time`, etc. etc. but I expect there is already a
> standard class or CRAN package.
>
>           -s
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to