[R] R timeDate does not allow seconds?

jim holtman jholtman at gmail.com
Fri Nov 2 22:25:41 CET 2007


Seems to work fine with this call:

> inputdate = "2007-10-31_16.20.22"
> timeDate(as.character(inputdate),format="%Y-%m-%d_%H.%M.%S")
GMT
[1] [2007-10-31 16:20:22]
>


On 11/2/07, B. Bogart <bbogart at sfu.ca> wrote:
> Hello all, Sorry if anyone gets this message twice, as my mailserver may
> not be working.
>
> Thanks for your response. Your idea makes a lot of sense to me, but I've
> been unable to get seconds to work.
>
> I ended up with this format finally:
>
> "2007-10-31_16:20:22"
>
> Problem is I am unable to get it recognized as a date using timeDate():
>
> R>
> timeDate(as.character(inputdate),format="%Y-%02m-%02d_%02H.%02M.%02S")
> Error in if (regexpr("/....", charvec[1])[[1]] > 0) return("%m/%d/%Y") :
>        missing value where TRUE/FALSE needed
>
> The R-help archives said something about non-standard formats casuing a
> problem, but I believe (short of the underscore) that its the seconds,
> not the delimiter that is causing the trouble.
>
> I've also been playing with zoo and its functions without much success
> either. The timeDate approach seems simplest.
>
> With so many date classes/methods in R, what is considered the standard
> way of dealing with it? I need to timezone or daylight saving stuff
> really, but seconds are imperative! (actually I've ended up with
> multiple events per second, which could cause future troubles, so msec
> may even be needed.
>
> Thanks,
> B. Bogart
>
> Following are all my attempts to get R to read seconds (with timeDate):
>
>
> > data[1,1] -> inputdate
> > inputdate
> [1] "2007-10-31_16:20:22"
> > inputdate = "2007-10-31_16.20.22"
> > timeDate(as.character(inputdate),format="%Y-%02m-%02d_%02H.%02M.%02S")
> Error in if (regexpr("/....", charvec[1])[[1]] > 0) return("%m/%d/%Y") :
>        missing value where TRUE/FALSE needed
> > inputdate = "2007-10-31_16-20-22"
> > timeDate(as.character(inputdate),format="%Y-%02m-%02d_%02H-%02M-%02S")
> Error in if (regexpr("/....", charvec[1])[[1]] > 0) return("%m/%d/%Y") :
>        missing value where TRUE/FALSE needed
> > inputdate = "16:20:22_2007-10-31"
> > timeDate(as.character(inputdate),format="%02H:%02M:%02S_%Y-%02m-%02d")
> Error in if (regexpr("/....", charvec[1])[[1]] > 0) return("%m/%d/%Y") :
>        missing value where TRUE/FALSE needed
> > inputdate = "16-20-22_2007-10-31"
> > timeDate(as.character(inputdate),format="%02H-%02M-%02S_%Y-%02m-%02d")
> Error in if (regexpr("/....", charvec[1])[[1]] > 0) return("%m/%d/%Y") :
>        missing value where TRUE/FALSE needed
> > inputdate = "16.20.22_2007-10-31"
> > timeDate(as.character(inputdate),format="%02H.%02M.%02S_%Y-%02m-%02d")
> Error in if (regexpr("/....", charvec[1])[[1]] > 0) return("%m/%d/%Y") :
>        missing value where TRUE/FALSE needed
> > inputdate = "16/20/22 2007/10/31"
> > timeDate(as.character(inputdate),format="%02H/%02M/%02S %Y/%02m/%02d")
> Error in if (regexpr("/....", charvec[1])[[1]] > 0) return("%m/%d/%Y") :
>        missing value where TRUE/FALSE needed
> > inputdate = "16.20.22 2007-10-31"
> > timeDate(as.character(inputdate),format="%02H.%02M.%02S %Y-%02m-%02d")
> Error in if (regexpr("/....", charvec[1])[[1]] > 0) return("%m/%d/%Y") :
>        missing value where TRUE/FALSE needed
>
> ______________________________________________
> R-help at 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.
>


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

What is the problem you are trying to solve?



More information about the R-help mailing list