[R] Formatting of time strings

Gabor Grothendieck ggrothendieck at gmail.com
Sat Sep 11 01:08:53 CEST 2010


On Fri, Sep 10, 2010 at 6:41 PM, Dennis Fisher <fisher at plessthan.com> wrote:
> Colleagues,
>
> (OS X, R: 11.1)
>
> I am stuck on what should be a simple problem.
>
> I have time elements in numeric form (e.g., 14050.5).  I want to convert these to HH:MM (e.g., 12:00).  I can do this
> with brute force (7 commands) but I suspect that it can be accomplished with a single command.  Any help would be appreciated.

There is more than one date and time representation in R but assuming
yours is expressed in days and fraction of day and you just want the
time portion ignoring the date portion:

> library(chron)
> format(times(14050.5 %% 1), simplify = TRUE)
[1] "12:00"



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list