Convert an "sts" Object to "ts" or "xts"
sts_coerce.RdThese methods convert surveillance time series objects of class
"sts" to the standard "ts" and
"xts" classes.
Conversion to and from ts is also possible using S4-type
coerce methods, e.g., as(x, "ts").
Arguments
- x
an object of class
"sts".- order.by
optional
Dates indexing the time series. The default is only used for weekly (freq=52) and daily (freq=365) data. If not specified, other frequencies are handled viaas.xts.ts.- ...
further arguments are ignored by the
as.tsmethod and passed toxtsby theas.xtsmethod.
Examples
## convert "ts"/"mts" object to "sts"
counts <- matrix(rpois(28*3,10), 28, 3,
dimnames = list(NULL, paste("Region", 1:3)))
z <- ts(counts, start = c(1983, 12), frequency = 12)
head(z)
x <- as(z, "sts")
x
## direct "sts" construction gives the same:
(x2 <- sts(counts, start = start(z), frequency = frequency(z)))
## conversion of "sts" objects to the "xts" class
if (require("xts")) {
y <- as.xts(x)
print(head(y))
plot(y)
}