EVOLUTION-MANAGER
Edit File: scale.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: Scaling and Centering of Matrix-like 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 scale {base}"><tr><td>scale {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Scaling and Centering of Matrix-like Objects</h2> <h3>Description</h3> <p><code>scale</code> is generic function whose default method centers and/or scales the columns of a numeric matrix. </p> <h3>Usage</h3> <pre> scale(x, center = TRUE, scale = TRUE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>a numeric matrix(like object).</p> </td></tr> <tr valign="top"><td><code>center</code></td> <td> <p>either a logical value or numeric-alike vector of length equal to the number of columns of <code>x</code>, where ‘numeric-alike’ means that <code><a href="numeric.html">as.numeric</a>(.)</code> will be applied successfully if <code><a href="numeric.html">is.numeric</a>(.)</code> is not true.</p> </td></tr> <tr valign="top"><td><code>scale</code></td> <td> <p>either a logical value or a numeric-alike vector of length equal to the number of columns of <code>x</code>.</p> </td></tr> </table> <h3>Details</h3> <p>The value of <code>center</code> determines how column centering is performed. If <code>center</code> is a numeric-alike vector with length equal to the number of columns of <code>x</code>, then each column of <code>x</code> has the corresponding value from <code>center</code> subtracted from it. If <code>center</code> is <code>TRUE</code> then centering is done by subtracting the column means (omitting <code>NA</code>s) of <code>x</code> from their corresponding columns, and if <code>center</code> is <code>FALSE</code>, no centering is done. </p> <p>The value of <code>scale</code> determines how column scaling is performed (after centering). If <code>scale</code> is a numeric-alike vector with length equal to the number of columns of <code>x</code>, then each column of <code>x</code> is divided by the corresponding value from <code>scale</code>. If <code>scale</code> is <code>TRUE</code> then scaling is done by dividing the (centered) columns of <code>x</code> by their standard deviations if <code>center</code> is <code>TRUE</code>, and the root mean square otherwise. If <code>scale</code> is <code>FALSE</code>, no scaling is done. </p> <p>The root-mean-square for a (possibly centered) column is defined as <i>sqrt(sum(x^2)/(n-1))</i>, where <i>x</i> is a vector of the non-missing values and <i>n</i> is the number of non-missing values. In the case <code>center = TRUE</code>, this is the same as the standard deviation, but in general it is not. (To scale by the standard deviations without centering, use <code>scale(x, center = FALSE, scale = apply(x, 2, sd, na.rm = TRUE))</code>.) </p> <h3>Value</h3> <p>For <code>scale.default</code>, the centered, scaled matrix. The numeric centering and scalings used (if any) are returned as attributes <code>"scaled:center"</code> and <code>"scaled:scale"</code> </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="sweep.html">sweep</a></code> which allows centering (and scaling) with arbitrary statistics. </p> <p>For working with the scale of a plot, see <code><a href="../../graphics/html/par.html">par</a></code>. </p> <h3>Examples</h3> <pre> require(stats) x <- matrix(1:10, ncol = 2) (centered.x <- scale(x, scale = FALSE)) cov(centered.scaled.x <- scale(x)) # all 1 </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>