[R] Chron format question h:m not working

David Winsemius dwinsemius at comcast.net
Wed May 1 20:49:33 CEST 2013


On May 1, 2013, at 10:55 AM, Stephen Sefick wrote:

> Thanks for the quick replies.  I have this working with a similar
> suggestion to what arun suggests.  I am just interested in why the option
> to use just h:m isn't supported.
> 
> #re: Jeff
> chron(dates.="2009/05/01", times.="15:00:00", format=c(dates=c("y/m/d"),
> times="h:m:s"))
> chron(dates.="2009/05/01", times.="15:00", format=c(dates=c("y/m/d"),
> times="h:m"))

Hard to say "why" but you should note that "h:m" is NOT a permutation of {h,m s} so this behavior really is not contravening the documentation. I check to see of out.format might be different since the format spec is really for input rather than output and it does not accept a two parameter version either:

Error in chron(dates = dts, times = tms, out.format = (times = "h:m")) : 
  misspecified chron format(s) length

> 
> same outcome.
> 
> Does updating to R 3.0.0 solve the problem?

The documentation did not change in the version that was updated to work with 3.0.0.

-- 
David.


> 
> Thanks for all of the help.
> 
> Stephen
> 
> 
> 
> On Wed, May 1, 2013 at 12:36 PM, arun <smartpink111 at yahoo.com> wrote:
> 
>> HI,
>> 
>> One possible way would be to use paste()
>> chron(times.=paste0("15:00",":00"),format=c(times="h:m:s"))
>> #[1] 15:00:00
>> 
>> 
>> #or you could use
>> 
>> library(lubridate)
>> hm("15:00")
>> #[1] "15H 0M 0S"
>> A.K.
>> 
>> 
>> 
>> ----- Original Message -----
>> From: Stephen Sefick <sas0025 at auburn.edu>
>> To: "r-help at r-project.org" <r-help at r-project.org>
>> Cc:
>> Sent: Wednesday, May 1, 2013 12:28 PM
>> Subject: [R] Chron format question h:m not working
>> 
>> 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?
>> 
>> many thanks,
>> 
>> 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list