Rev 7002 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{ts}\title{Time-Series Objects}\usage{ts(data = NA, start = 1, end = numeric(0), frequency = 1,deltat = 1, ts.eps = .Options$ts.eps, class, names)as.ts(x)is.ts(x)print(ts.obj, calendar, ...)plot(ts.obj, plot.type=c("multiple", "single"), ...)lines(ts.obj, ...)}\alias{ts}\alias{as.ts}\alias{is.ts}\alias{print.ts}\alias{plot.ts}\alias{plot.mts}\alias{lines.ts}\arguments{\item{data}{a vector or matrix of the observed time-series values.}\item{start}{the time of the first observation. Either an integerwhich correspond or a vector of two integers, which give a naturaltime unit and a (1-based) number of samples into the time unit.}\item{end}{the time of the last observation, specified in the same wayas \code{start}.}\item{frequency}{the number of observations per unit of time.}\item{deltat}{the fraction of the sampling period between successiveobservations; e.g., 1/12 for monthly data.Only one of \code{frequency} or \code{deltat} should be provided.}\item{ts.eps}{time series comparison tolerance. Frequencies areconsidered equal if their absolute difference is less than\code{ts.eps}.}\item{class}{class to be given to the result, or none if \code{NULL}or \code{"none"}. The default is \code{"ts"} for a singleseries, \code{c("mts", "ts")} for multiple series.}\item{names}{a character vector of names for the series in amultiple series: defaults to the colnames of \code{data}, or\code{Series 1}, \code{Series 2}, \dots.}\item{calendar}{enable/disable the display of information aboutmonth names, quarter names or year when printing. The default is\code{TRUE} for a frequency of 4 or 12, \code{FALSE} otherwise.}\item{plot.type}{for multivariate time series, should the series byplotted separately (with a common time axis) or on a singleplot?}\item{\dots}{additional arguments to print or plot.}}\description{The function \code{ts} is used to create time-series objects.\code{as.ts} and \code{is.ts} coerce an object to atime-series and test whether an object is a time series.}\details{The function \code{ts} is used to create time-series objects. Theseare vector or matrices with class of \code{"ts"} (and additionalattributes) which represent data which has been sampled at equispacedpoints in time. In the matrix case, each column of the matrix\code{data} is assumed to contain a single (univariate) time series.Class \code{"ts"} has a number of methods. In particular arithmeticwill attempt to align time axes, and subsetting to extractsubsets of series can be used (e.g. \code{EuStockMarkets[, "DAX"]}).However, subsetting the first (or only) dimension will return amatrix or vector, as will matrix subsetting.The value of argument \code{frequency} is used when the series issampled an integral number of times in each unit time interval. Forexample, one could use a value of \code{7} for \code{frequency} whenthe data are sampled daily, and the natural time period is a week, or\code{12} when the data are sampled monthly and the natural timeperiod is a year. Values of \code{4} and \code{12} are assumed in (e.g.)\code{print} methods to imply a quarterly and monthly series respectively.\code{as.ts} will use the \code{\link{tsp}} attribute of the object ifit has one to set the start and end times and frequency.}\seealso{\code{\link{tsp}},\code{\link{frequency}},\code{\link{start}},\code{\link{end}},\code{\link{time}},\code{\link{window}}Standard package \code{ts} for many additional time-series functions.}\examples{ts(1:10, frequency = 4, start = c(1959, 2)) # 2nd Quarter of 1959print( ts(1:10, freq = 7, start = c(12, 2)), calendar = TRUE) # print.ts(.)## Using July 1954 as start date:gnp <- ts(cumsum(1 + round(rnorm(100), 2)),start = c(1954, 7), frequency = 12)plot(gnp) # using `plot.ts' for time-series plot## Multivariatez <- ts(matrix(rnorm(300),100,3), start=c(1961,1), frequency=12)plot(z)plot(z, plot.type="single", lty=1:3)\testonly{ts(1:5, start=2, end=4) # truncatets(1:5, start=3, end=17)# repeatall(z==z)all(z-z == 0)}## A phase plot:data(nhtemp)plot(nhtemp, c(nhtemp[-1],NA), cex = .8, col="blue",main="Lag plot of New Haven temperatures")## a clearer way to do this would be\dontrun{library(ts)plot(nhtemp, lag(nhtemp,1), cex = .8, col="blue",main="Lag plot of New Haven temperatures")}}\keyword{ts}