EVOLUTION-MANAGER
Edit File: zooreg.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: Regular zoo Series</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 zooreg {zoo}"><tr><td>zooreg {zoo}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Regular zoo Series</h2> <h3>Description</h3> <p><code>zooreg</code> is the creator for the S3 class <code>"zooreg"</code> for regular <code>"zoo"</code> series. It inherits from <code>"zoo"</code> and is the analogue to <code><a href="../../stats/html/ts.html">ts</a></code>. </p> <h3>Usage</h3> <pre> zooreg(data, start = 1, end = numeric(), frequency = 1, deltat = 1, ts.eps = getOption("ts.eps"), order.by = NULL, calendar = getOption("zoo.calendar", TRUE)) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>data</code></td> <td> <p>a numeric vector, matrix or a factor.</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.</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>order.by</code></td> <td> <p>a vector by which the observations in <code>x</code> are ordered. If this is specified the arguments <code>start</code> and <code>end</code> are ignored and <code>zoo(data, order.by, frequency)</code> is called. See <code><a href="zoo.html">zoo</a></code> for more information.</p> </td></tr> <tr valign="top"><td><code>calendar</code></td> <td> <p>logical. Should <code><a href="yearqtr.html">yearqtr</a></code> or <code><a href="yearmon.html">yearmon</a></code> be used for a numeric time index with frequency 4 or 12, respectively?</p> </td></tr> </table> <h3>Details</h3> <p>Strictly regular series are those whose time points are equally spaced. Weakly regular series are strictly regular time series in which some of the points may have been removed but still have the original underlying frequency associated with them. <code>"zooreg"</code> is a subclass of <code>"zoo"</code> that is used to represent both weakly and strictly regular series. Internally, it is the same as <code>"zoo"</code> except it also has a <code>"frequency"</code> attribute. Its index class is more restricted than <code>"zoo"</code>. The index: 1. must be numeric or a class which can be coerced via <code>as.numeric</code> (such as <code><a href="yearmon.html">yearmon</a></code>, <code><a href="yearqtr.html">yearqtr</a></code>, <code><a href="../../base/html/Dates.html">Date</a></code>, <code><a href="../../base/html/DateTimeClasses.html">POSIXct</a></code>, <code><a href="../../tis/html/tis.html">tis</a></code>, <code><a href="../../xts/html/xts.html">xts</a></code>, etc.). 2. when converted to numeric must be expressible as multiples of 1/frequency. 3. group generic functions <code><a href="../../methods/html/S4groupGeneric.html">Ops</a></code> should be defined, i.e., adding/subtracting a numeric to/from the index class should produce the correct value of the index class again. </p> <p><code>zooreg</code> is the <code>zoo</code> analogue to <code><a href="../../stats/html/ts.html">ts</a></code>. The arguments are almost identical, only in the case where <code>order.by</code> is specified, <code><a href="zoo.html">zoo</a></code> is called with <code>zoo(data, order.by, frequency)</code>. It creates a regular series of class <code>"zooreg"</code> which inherits from <code>"zoo"</code>. It is essentially a <code>"zoo"</code> series with an additional <code>"frequency"</code> attribute. In the creation of <code>"zooreg"</code> objects (via <code><a href="zoo.html">zoo</a></code>, <code><a href="zooreg.html">zooreg</a></code>, or coercion functions) it is always check whether the index specified complies with the frequency specified. </p> <p>The class <code>"zooreg"</code> offers two advantages over code <code>"ts"</code>: 1. The index does not have to be plain numeric (although that is the default), it just must be coercible to numeric, thus printing and plotting can be customized. 2. This class can not only represent strictly regular series, but also series with an underlying regularity, i.e., where some observations from a regular grid are omitted. </p> <p>Hence, <code>"zooreg"</code> is a bridge between <code>"ts"</code> and <code>"zoo"</code> and can be employed to coerce back and forth between the two classes. The coercion function <code>as.zoo.ts</code> returns therefore an object of class <code>"zooreg"</code> inheriting from <code>"zoo"</code>. Coercion between <code>"zooreg"</code> and <code>"zoo"</code> is also available and drops or tries to add a frequency respectively. </p> <p>For checking whether a series is strictly regular or does have an underlying regularity the generic function <code><a href="is.regular.html">is.regular</a></code> can be used. </p> <p>Methods to standard generics for regular series such as <code><a href="../../stats/html/time.html">frequency</a></code>, <code><a href="../../stats/html/time.html">deltat</a></code> and <code><a href="../../stats/html/time.html">cycle</a></code> are available for both <code>"zooreg"</code> and <code>"zoo"</code> objects. In the latter case, it is checked first (in a data-driven way) whether the series is in fact regular or not. </p> <p><code>as.zooreg.tis</code> has a <code>class</code> argument whose value represents the class of the index of the <code>zooreg</code> object into which the <code>tis</code> object is converted. The default value is <code>"ti"</code>. Note that the frequency of the <code>zooreg</code> object will not necessarily be the same as the frequency of the <code>tis</code> object that it is converted from. </p> <h3>Value</h3> <p>An object of class <code>"zooreg"</code> which inherits from <code>"zoo"</code>. It is essentially a <code>"zoo"</code> series with a <code>"frequency"</code> attribute. </p> <h3>See Also</h3> <p><code><a href="zoo.html">zoo</a></code>, <code><a href="is.regular.html">is.regular</a></code></p> <h3>Examples</h3> <pre> ## equivalent specifications of a quarterly series ## starting in the second quarter of 1959. zooreg(1:10, frequency = 4, start = c(1959, 2)) as.zoo(ts(1:10, frequency = 4, start = c(1959, 2))) zoo(1:10, seq(1959.25, 1961.5, by = 0.25), frequency = 4) ## use yearqtr class for indexing the same series z <- zoo(1:10, yearqtr(seq(1959.25, 1961.5, by = 0.25)), frequency = 4) z z[-(3:4)] ## create a regular series with a "Date" index zooreg(1:5, start = as.Date("2000-01-01")) ## or with "yearmon" index zooreg(1:5, end = yearmon(2000)) ## lag and diff (as diff is defined in terms of lag) ## act differently on zoo and zooreg objects! ## lag.zoo moves a point to the adjacent time whereas ## lag.zooreg moves a point by deltat x <- c(1, 2, 3, 6) zz <- zoo(x, x) zr <- as.zooreg(zz) lag(zz, k = -1) lag(zr, k = -1) diff(zz) diff(zr) ## lag.zooreg wihtout and with na.pad lag(zr, k = -1) lag(zr, k = -1, na.pad = TRUE) ## standard methods available for regular series frequency(z) deltat(z) cycle(z) cycle(z[-(3:4)]) zz <- zoo(1:6, as.Date(c("1960-01-29", "1960-02-29", "1960-03-31", "1960-04-29", "1960-05-31", "1960-06-30"))) # this converts zz to "zooreg" and then to "ts" expanding it to a daily # series which is 154 elements long, most with NAs. ## Not run: length(as.ts(zz)) # 154 ## End(Not run) # probably a monthly "ts" series rather than a daily one was wanted. # This variation of the last line gives a result only 6 elements long. length(as.ts(aggregate(zz, as.yearmon, c))) # 6 zzr <- as.zooreg(zz) dd <- as.Date(c("2000-01-01", "2000-02-01", "2000-03-01", "2000-04-01")) zrd <- as.zooreg(zoo(1:4, dd)) </pre> <hr /><div style="text-align: center;">[Package <em>zoo</em> version 1.8-11 <a href="00Index.html">Index</a>]</div> </body></html>