[R] POSIX to ts and back to POSIX

Allen.Joel@epamail.epa.gov Allen.Joel at epamail.epa.gov
Wed May 19 21:24:38 CEST 2004





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]
> as.POSIXct(ts(as.POSIXct(strptime(tmp,"%m/%d/%Y
%H:%M:%S")),freq=1440))
Error in as.POSIXct.default(ts(as.POSIXct(strptime(tmp, "%m/%d/%Y
%H:%M:%S")),  :
      Don't know how to convert `ts(as.POSIXct(strptime(tmp, "%m/%d/%Y
%H:%M:%S")), freq = 1440)' to class "POSIXct"

this does not work either

> as.POSIXct(as.numeric(as.POSIXct(strptime(tmp,"%m/%d/%Y %H:%M:%S"))))
Error in as.POSIXct.default(as.numeric(as.POSIXct(strptime(tmp,
"%m/%d/%Y %H:%M:%S")))) :
      Don't know how to convert `as.numeric(as.POSIXct(strptime(tmp,
"%m/%d/%Y %H:%M:%S")))' to class "POSIXct"

Thanks in advance.

H. Joel Allen, PhD
Environmental Scientist
U.S. EPA
NRMRL, Water Quality Management Branch
26 W. Martin Luther King Dr
Cincinnati, OH 45268

Phone: 513 487-2806
Fax: 513 569-7052
Email: allen.joel at epa.gov




More information about the R-help mailing list