EVOLUTION-MANAGER
Edit File: sweep.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: Sweep out Array Summaries</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 sweep {base}"><tr><td>sweep {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Sweep out Array Summaries</h2> <h3>Description</h3> <p>Return an array obtained from an input array by sweeping out a summary statistic. </p> <h3>Usage</h3> <pre> sweep(x, MARGIN, STATS, FUN = "-", check.margin = TRUE, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>an array.</p> </td></tr> <tr valign="top"><td><code>MARGIN</code></td> <td> <p>a vector of indices giving the extent(s) of <code>x</code> which correspond to <code>STATS</code>.</p> </td></tr> <tr valign="top"><td><code>STATS</code></td> <td> <p>the summary statistic which is to be swept out.</p> </td></tr> <tr valign="top"><td><code>FUN</code></td> <td> <p>the function to be used to carry out the sweep.</p> </td></tr> <tr valign="top"><td><code>check.margin</code></td> <td> <p>logical. If <code>TRUE</code> (the default), warn if the length or dimensions of <code>STATS</code> do not match the specified dimensions of <code>x</code>. Set to <code>FALSE</code> for a small speed gain when you <em>know</em> that dimensions match.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>optional arguments to <code>FUN</code>.</p> </td></tr> </table> <h3>Details</h3> <p><code>FUN</code> is found by a call to <code><a href="match.fun.html">match.fun</a></code>. As in the default, binary operators can be supplied if quoted or backquoted. </p> <p><code>FUN</code> should be a function of two arguments: it will be called with arguments <code>x</code> and an array of the same dimensions generated from <code>STATS</code> by <code><a href="aperm.html">aperm</a></code>. </p> <p>The consistency check among <code>STATS</code>, <code>MARGIN</code> and <code>x</code> is stricter if <code>STATS</code> is an array than if it is a vector. In the vector case, some kinds of recycling are allowed without a warning. Use <code>sweep(x, MARGIN, as.array(STATS))</code> if <code>STATS</code> is a vector and you want to be warned if any recycling occurs. </p> <h3>Value</h3> <p>An array with the same shape as <code>x</code>, but with the summary statistics swept out. </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="apply.html">apply</a></code> on which <code>sweep</code> used to be based; <code><a href="scale.html">scale</a></code> for centering and scaling. </p> <h3>Examples</h3> <pre> require(stats) # for median med.att <- apply(attitude, 2, median) sweep(data.matrix(attitude), 2, med.att) # subtract the column medians ## More sweeping: A <- array(1:24, dim = 4:2) ## no warnings in normal use sweep(A, 1, 5) (A.min <- apply(A, 1, min)) # == 1:4 sweep(A, 1, A.min) sweep(A, 1:2, apply(A, 1:2, median)) ## warnings when mismatch sweep(A, 1, 1:3) # STATS does not recycle sweep(A, 1, 6:1) # STATS is longer ## exact recycling: sweep(A, 1, 1:2) # no warning sweep(A, 1, as.array(1:2)) # warning </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>