ts
Time Series Objects

Description

Defines a univariate or multivariate time series.

Usage

ts(data = NA, start = 1, end = numeric(0), frequency = 1, 
    deltat = 1, ts.eps = getOption("ts.eps"),
    class = if(nseries > 1) c("mts", "ts", "matrix") else "ts",
    names = if(!is.null(dimnames(data))) colnames(data)
        else paste("Series", seq(nseries)))    
is.ts(x)
is.mts(x)
as.ts(x)

Arguments

x any TIBCO Enterprise Runtime for R object.
data a vector or a matrix giving the data values for the time series. If a matrix, each column represents one series of a multivariate time series.

Missing values (NA) are allowed. data must have one or more observations.

start starting date for the series. For example, in years, February, 1970 is 1970+(1/12) or 1970.083. If start is a vector with at least two data values, the first is interpreted as the time unit (for example, the year), and the second as the number of positions into the sampling period. For example, February, 1970 could be c(1970,2). If both start and end are missing, then start defaults to 1.
frequency observations frequency; that is, how many observations per sampling period. For example, monthly data have frequency=12.
end ending date for the series. If this is given, it and the length of data are used to compute start. if both end and start are given, end must be bigger than start.
deltat argument to be provided instead of frequency. This represents the fraction of the sampling period between successive observations; e.g., monthly data has deltat=1/12. Only one of frequency or deltat should be provided.
names used only when data is a matrix. A vector containing character strings to be used as names for the component series of the multivariate series. By default, the strings "Series i" i=1,2,…, ncol(data) are used as series names (columns of data) unless data has an associated dimnames attribute which is retained by the resulting time series.
ts.eps time series comparison tolerance. This small number is used throughout the time series functions for comparison of their frequencies. It defaults to .Options\$ts.eps=1e-5 which means that frequencies will be considered equal if they correspond up to their 5th decimal, if a fraction.
class a character vector. Specifies the class name. By default, if the number of columns in data is greater than 1, then the class of time series is c("mts","ts","matrix"). Otherwise, the class of the time series is "ts".

Details

Any periodic data can be organized as a time series. Hourly data might use days for start and end with frequency=24 or deltat=1/24; daily data could use weeks with frequency=7 or deltat=1/7.
There is special printing for the cases of frequency=4 or 12 (see print.ts).
Time series objects are those that have an attribute tsp, which must be numeric of length 3. Multivariate time series objects also have attributes dim and (possibly) dimnames.
Multivariate time series are printed by default like a matrix with the tsp attribute printed last. Calling print.ts directly provides an alternative.
Value
tsreturns a time series containing the given data. Time series attributes are assigned consistently with whichever of start, end, and frequency are supplied. If frequency is supplied, then only one of start or end is needed, because the other parameter is computed based on the given values and length(data) (or nrow(data)). If both start and end are omitted, the series is started at 1. ts checks that the arguments supplied are consistent.
is.tsreturns TRUE if x is a time series object (that is, if it has a tsp attribute). Otherwise, returns FALSE.
as.tsreturns a time series.
is.mtsreturns TRUE if x inherits from "mts".
See Also
tsp gives the start and end times and the frequency. window is used for subsetting, as the "[" operator drops all time series attributes from its result.
Examples
# Monthly univariate data starting October 1066:
ts(101:125, start=c(1066, 10), frequency=12)
# Another way to create the same thing
ts(101:125, end=1068+9/12, frequency=12)
# Quarterly numbers for three regions
ts(cbind(North=11:17, South=21:27, West=14:20), start=2012.25, frequency=4)
Package stats version 6.0.0-69
Package Index