[R] POSIX to ts and back to POSIX

Jason Turner jasont at indigoindustrial.co.nz
Thu May 20 17:33:19 CEST 2004


On Wed, May 19, 2004 at 03:24:38PM -0400, Allen.Joel at epamail.epa.gov wrote:
> I am trying to use POSIX datetime objects rather than chron datetime
> objects but am having difficulty with POSIX in a time series.  My
> question:  Once a POSIXct vector is bound to a time series, is there a
> function to convert back to POSIXct?  The following code demonstrates
> what I am trying to do.
> 
> > ts(as.POSIXct(strptime(tmp,"%m/%d/%Y %H:%M:%S")),freq=1440)
> Time Series:
> Start = c(1, 1)
> End = c(1, 10)
> Frequency = 1440
>  [1] 1074022572 1074022632 1074022693 1074022753 1074022813 1074022874
> 1074022934 1074022994 1074023055 1074023115
> attr(,"tzone")
> [1]
...

for the reverse process, something like....

## UNTESTED!
yourts <- ts(as.POSIXct(strptime(tmp,"%m/%d/%Y %H:%M:%S")),freq=1440)
ISOdate(1970,1,1,0,0,0,UTC) + time(yourts)

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
http://www.indigoindustrial.co.nz
64-21-343-545
jasont at indigoindustrial.co.nz




More information about the R-help mailing list