EVOLUTION-MANAGER
Edit File: vaggregate.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: Vector aggregate.</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 vaggregate {plyr}"><tr><td>vaggregate {plyr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Vector aggregate.</h2> <h3>Description</h3> <p>This function is somewhat similar to <code>tapply</code>, but is designed for use in conjunction with <code>id</code>. It is simpler in that it only accepts a single grouping vector (use <code><a href="id.html">id</a></code> if you have more) and uses <code><a href="../../base/html/lapply.html">vapply</a></code> internally, using the <code>.default</code> value as the template. </p> <h3>Usage</h3> <pre> vaggregate(.value, .group, .fun, ..., .default = NULL, .n = nlevels(.group)) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>.value</code></td> <td> <p>vector of values to aggregate</p> </td></tr> <tr valign="top"><td><code>.group</code></td> <td> <p>grouping vector</p> </td></tr> <tr valign="top"><td><code>.fun</code></td> <td> <p>aggregation function</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>other arguments passed on to <code>.fun</code></p> </td></tr> <tr valign="top"><td><code>.default</code></td> <td> <p>default value used for missing groups. This argument is also used as the template for function output.</p> </td></tr> <tr valign="top"><td><code>.n</code></td> <td> <p>total number of groups</p> </td></tr> </table> <h3>Details</h3> <p><code>vaggregate</code> should be faster than <code>tapply</code> in most situations because it avoids making a copy of the data. </p> <h3>Examples</h3> <pre> # Some examples of use borrowed from ?tapply n <- 17; fac <- factor(rep(1:3, length.out = n), levels = 1:5) table(fac) vaggregate(1:n, fac, sum) vaggregate(1:n, fac, sum, .default = NA_integer_) vaggregate(1:n, fac, range) vaggregate(1:n, fac, range, .default = c(NA, NA) + 0) vaggregate(1:n, fac, quantile) # Unlike tapply, vaggregate does not support multi-d output: tapply(warpbreaks$breaks, warpbreaks[,-1], sum) vaggregate(warpbreaks$breaks, id(warpbreaks[,-1]), sum) # But it is about 10x faster x <- rnorm(1e6) y1 <- sample.int(10, 1e6, replace = TRUE) system.time(tapply(x, y1, mean)) system.time(vaggregate(x, y1, mean)) </pre> <hr /><div style="text-align: center;">[Package <em>plyr</em> version 1.8.7 <a href="00Index.html">Index</a>]</div> </body></html>