| sts_conversion | R Documentation |
"sts" Object to "ts" or "xts"
These 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").
## S3 method for class 'sts'
as.ts(x, ...)
## S3 method for class 'sts'
as.xts(x, order.by = epoch(x, as.Date = TRUE), ...)
x |
an object of class |
order.by |
optional |
... |
further arguments are ignored by the |
an object of class "ts" or "xts",
respectively.
## 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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.