EVOLUTION-MANAGER
Edit File: rollmean.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: Rolling Means/Maximums/Medians/Sums</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 rollmean {zoo}"><tr><td>rollmean {zoo}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Rolling Means/Maximums/Medians/Sums</h2> <h3>Description</h3> <p>Generic functions for computing rolling means, maximums, medians, and sums of ordered observations. </p> <h3>Usage</h3> <pre> rollmean(x, k, fill = if (na.pad) NA, na.pad = FALSE, align = c("center", "left", "right"), ...) rollmax(x, k, fill = if (na.pad) NA, na.pad = FALSE, align = c("center", "left", "right"), ...) rollmedian(x, k, fill = if (na.pad) NA, na.pad = FALSE, align = c("center", "left", "right"), ...) rollsum(x, k, fill = if (na.pad) NA, na.pad = FALSE, align = c("center", "left", "right"), ...) rollmeanr(..., align = "right") rollmaxr(..., align = "right") rollmedianr(..., align = "right") rollsumr(..., align = "right") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>an object (representing a series of observations).</p> </td></tr> <tr valign="top"><td><code>k</code></td> <td> <p>integer width of the rolling window. Must be odd for <code>rollmedian</code>.</p> </td></tr> <tr valign="top"><td><code>fill</code></td> <td> <p>a three-component vector or list (recycled otherwise) providing filling values at the left/within/to the right of the data range. See the <code>fill</code> argument of <code><a href="na.fill.html">na.fill</a></code> for details.</p> </td></tr> <tr valign="top"><td><code>na.pad</code></td> <td> <p>deprecated. Use <code>fill = NA</code> instead of <code>na.pad = TRUE</code>.</p> </td></tr> <tr valign="top"><td><code>align</code></td> <td> <p>character specifying whether the index of the result should be left- or right-aligned or centered (default) compared to the rolling window of observations.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Further arguments passed to methods.</p> </td></tr> </table> <h3>Details</h3> <p>These functions compute rolling means, maximums, medians, and sums respectively and are thus similar to <code><a href="rollapply.html">rollapply</a></code> but are optimized for speed. </p> <p>Currently, there are methods for <code>"zoo"</code> and <code>"ts"</code> series and default methods. The default method of <code>rollmedian</code> is an interface to <code><a href="../../stats/html/runmed.html">runmed</a></code>. The default methods of <code>rollmean</code> and <code>rollsum</code> do not handle inputs that contain <code>NA</code>s. In such cases, use <code><a href="rollapply.html">rollapply</a></code> instead. </p> <p>If <code>x</code> is of length 0, <code>x</code> is returned unmodified. </p> <h3>Value</h3> <p>An object of the same class as <code>x</code> with the rolling mean/max/median/sum. </p> <h3>See Also</h3> <p><code><a href="rollapply.html">rollapply</a></code>, <code><a href="zoo.html">zoo</a></code>, <code><a href="na.fill.html">na.fill</a></code></p> <h3>Examples</h3> <pre> suppressWarnings(RNGversion("3.5.0")) set.seed(1) x.Date <- as.Date(paste(2004, rep(1:4, 4:1), sample(1:28, 10), sep = "-")) x <- zoo(rnorm(12), x.Date) ## rolling operations for univariate series rollmean(x, 3) rollmax(x, 3) rollmedian(x, 3) rollsum(x, 3) ## rolling operations for multivariate series xm <- zoo(matrix(1:12, 4, 3), x.Date[1:4]) rollmean(xm, 3) rollmax(xm, 3) rollmedian(xm, 3) rollsum(xm, 3) ## rollapply vs. dedicated rollmean rollapply(xm, 3, mean) # uses rollmean rollapply(xm, 3, function(x) mean(x)) # does not use rollmean </pre> <hr /><div style="text-align: center;">[Package <em>zoo</em> version 1.8-11 <a href="00Index.html">Index</a>]</div> </body></html>