Re: [R] POSIX to ts and back to POSIX

About this list Date view Thread view Subject view Author view Attachment view

From: Gabor Grothendieck (ggrothendieck@myway.com)
Date: Thu 20 May 2004 - 11:30:05 EST


Message-id: <loom.20040520T032505-31@post.gmane.org>

Is your question how to convert a vector v containing
seconds since the Epoch to POSIXct? If that's it, then
one way is:

now <- Sys.time()
Epoch <- now - as.numeric(now)
Epoch + v

 <Allen.Joel <at> epamail.epa.gov> writes:
:
: 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
:
: ______________________________________________
: R-help <at> stat.math.ethz.ch mailing list
: https://www.stat.math.ethz.ch/mailman/listinfo/r-help
: PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
:
:

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:11 EST