EVOLUTION-MANAGER
Edit File: ts.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Time-Series Objects</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for ts {stats}"><tr><td>ts {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Time-Series Objects</h2> <h3>Description</h3> <p>The function <code>ts</code> is used to create time-series objects. </p> <p><code>as.ts</code> and <code>is.ts</code> coerce an object to a time-series and test whether an object is a time series. </p> <h3>Usage</h3> <pre> ts(data = NA, start = 1, end = numeric(), frequency = 1, deltat = 1, ts.eps = getOption("ts.eps"), class = , names = ) as.ts(x, ...) is.ts(x) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>data</code></td> <td> <p>a vector or matrix of the observed time-series values. A data frame will be coerced to a numeric matrix via <code>data.matrix</code>. (See also ‘Details’.)</p> </td></tr> <tr valign="top"><td><code>start</code></td> <td> <p>the time of the first observation. Either a single number or a vector of two integers, which specify a natural time unit and a (1-based) number of samples into the time unit. See the examples for the use of the second form.</p> </td></tr> <tr valign="top"><td><code>end</code></td> <td> <p>the time of the last observation, specified in the same way as <code>start</code>.</p> </td></tr> <tr valign="top"><td><code>frequency</code></td> <td> <p>the number of observations per unit of time.</p> </td></tr> <tr valign="top"><td><code>deltat</code></td> <td> <p>the fraction of the sampling period between successive observations; e.g., 1/12 for monthly data. Only one of <code>frequency</code> or <code>deltat</code> should be provided.</p> </td></tr> <tr valign="top"><td><code>ts.eps</code></td> <td> <p>time series comparison tolerance. Frequencies are considered equal if their absolute difference is less than <code>ts.eps</code>.</p> </td></tr> <tr valign="top"><td><code>class</code></td> <td> <p>class to be given to the result, or none if <code>NULL</code> or <code>"none"</code>. The default is <code>"ts"</code> for a single series, <code>c("mts", "ts", "matrix")</code> for multiple series.</p> </td></tr> <tr valign="top"><td><code>names</code></td> <td> <p>a character vector of names for the series in a multiple series: defaults to the colnames of <code>data</code>, or <code>Series 1</code>, <code>Series 2</code>, ....</p> </td></tr> <tr valign="top"><td><code>x</code></td> <td> <p>an arbitrary <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>arguments passed to methods (unused for the default method).</p> </td></tr> </table> <h3>Details</h3> <p>The function <code>ts</code> is used to create time-series objects. These are vectors or matrices with class of <code>"ts"</code> (and additional attributes) which represent data which has been sampled at equispaced points in time. In the matrix case, each column of the matrix <code>data</code> is assumed to contain a single (univariate) time series. Time series must have at least one observation, and although they need not be numeric there is very limited support for non-numeric series. </p> <p>Class <code>"ts"</code> has a number of methods. In particular arithmetic will attempt to align time axes, and subsetting to extract subsets of series can be used (e.g., <code>EuStockMarkets[, "DAX"]</code>). However, subsetting the first (or only) dimension will return a matrix or vector, as will matrix subsetting. Subassignment can be used to replace values but not to extend a series (see <code><a href="window.html">window</a></code>). There is a method for <code><a href="../../base/html/t.html">t</a></code> that transposes the series as a matrix (a one-column matrix if a vector) and hence returns a result that does not inherit from class <code>"ts"</code>. </p> <p>The value of argument <code>frequency</code> is used when the series is sampled an integral number of times in each unit time interval. For example, one could use a value of <code>7</code> for <code>frequency</code> when the data are sampled daily, and the natural time period is a week, or <code>12</code> when the data are sampled monthly and the natural time period is a year. Values of <code>4</code> and <code>12</code> are assumed in (e.g.) <code>print</code> methods to imply a quarterly and monthly series respectively. </p> <p><code>as.ts</code> is generic. Its default method will use the <code><a href="tsp.html">tsp</a></code> attribute of the object if it has one to set the start and end times and frequency. </p> <p><code>is.ts</code> tests if an object is a time series. It is generic: you can write methods to handle specific classes of objects, see <a href="../../base/html/InternalMethods.html">InternalMethods</a>. </p> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="tsp.html">tsp</a></code>, <code><a href="time.html">frequency</a></code>, <code><a href="start.html">start</a></code>, <code><a href="start.html">end</a></code>, <code><a href="time.html">time</a></code>, <code><a href="window.html">window</a></code>; <code><a href="print.ts.html">print.ts</a></code>, the print method for time series objects; <code><a href="plot.ts.html">plot.ts</a></code>, the plot method for time series objects. </p> <p>For other definitions of ‘time series’ (e.g., time-ordered observations) see the CRAN task view at <a href="https://CRAN.R-project.org/view=TimeSeries">https://CRAN.R-project.org/view=TimeSeries</a>. </p> <h3>Examples</h3> <pre> require(graphics) ts(1:10, frequency = 4, start = c(1959, 2)) # 2nd Quarter of 1959 print( ts(1:10, frequency = 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 ## Multivariate z <- ts(matrix(rnorm(300), 100, 3), start = c(1961, 1), frequency = 12) class(z) head(z) # as "matrix" plot(z) plot(z, plot.type = "single", lty = 1:3) ## A phase plot: plot(nhtemp, lag(nhtemp, 1), cex = .8, col = "blue", main = "Lag plot of New Haven temperatures") </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>