Skip to contents

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").

Usage

# S3 method for class 'sts'
as.ts(x, ...)

# S3 method for class 'sts'
as.xts(x, order.by = epoch(x, as.Date = TRUE), ...)

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 via as.xts.ts.

...

further arguments are ignored by the as.ts method and passed to xts by the as.xts method.

Value

an object of class "ts" or "xts", respectively.

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)
}