## 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)))
stopifnot(identical(x, x2))
## conversion of "sts" objects to the "xts" class
if (require("xts")) {
y <- as.xts(x)
print(head(y))
plot(y)
}
Run the code above in your browser using DataLab