[R] ts vs. POSIX
Jason Turner
jasont at indigoindustrial.co.nz
Wed Oct 29 00:55:02 CET 2003
Erin Hodgess wrote:
> What if I have a time series which is collected every Monday, please?
>
> What is the proper way to use the start option within the ts command
> in order to indicate that this is Monday data, please?
>
ts objects don't directly support dates. There is some provision for
monthly data, but this isn't the same as uniform, across-the-board date
support. What they do have is a start time, a deltat, and frequency
(observations per period). The main reason to use ts objects *isn't*
the date/time handling, but for the nice functions (acf, spectrum, etc)
you can use for regularly spaces time samples.
For weekly data, I'd use one of the following approaches (assuming the
series starts in the first Monday of 2003):
1)
# dates in a year,week format
> foo <- ts(1:100,start=c(2003,1),frequency=52)
or
2)
# dates as numeric representation of POSIXct objects
foo <- ts(1:100,start=as.numeric(as.POSIXct("2003-1-6")),deltat=60*60*24*7)
> start(foo)
[1] 1041764400
> end(foo)
[1] 1101639600
> last <- end(foo)
> class(last) <- "POSIXct"
> last
[1] "2004-11-29 New Zealand Daylight Time"
(2) depends on as.numeric(POSIXct.object) giving a sensible,
single-digit answer. This is not guaranteed. It works today, but
nobody promised this approach would work tomorrow.
Hope that helps.
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