[R] R timeDate does not allow seconds?

B. Bogart bbogart at goto10.org
Fri Nov 2 16:48:48 CET 2007


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



More information about the R-help mailing list