[R] Chron format question h:m not working

Gabor Grothendieck ggrothendieck at gmail.com
Thu May 2 01:39:24 CEST 2013


On Wed, May 1, 2013 at 12:28 PM, Stephen Sefick <sas0025 at auburn.edu> wrote:
> R 2.12.2 on Scientific Linux 6.4
>
> #works
> chron(times.="15:00:00", format=c(times="h:m:s"))
>
> #doesn't work
> chron(times.="15:00", format=c(times="h:m"))
>
> From chron Manual:
> The times format can be any permutation of "h", "m", and "s" separated by
> any one non-special character. The default is "h:m:s".
>
> what am I missing?
>

1. Note that as.chron works so this converts it to a chron date/time
using today as the date part and then subtracts off the date part:

ch <- as.chron("15:00", "%H:%M")
ch - c(dates(ch))

An alternative to the last line that also works is:

times(as.numeric(ch) %% 1)

2. Here is yet another approach.  Since 1970-01-01 is internally
represented by chron as 0:

times(as.chron(paste0("1970-01-01 ", "15:00", ":00")))

3. and another which is a mix of the above two:

times(as.chron(paste(chron(0), "15:00"), "%m/%d/%y %H:%S"))




--
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