Rev 49852 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/scale.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2009 R Core Development Team% Distributed under GPL 2 or later\name{scale}\alias{scale}\alias{scale.default}\title{Scaling and Centering of Matrix-like Objects}\description{\code{scale} is generic function whose default method centers and/orscales the columns of a numeric matrix.}\usage{scale(x, center = TRUE, scale = TRUE)}\arguments{\item{x}{a numeric matrix(like object).}\item{center}{either a logical value or a numeric vector of lengthequal to the number of columns of \code{x}.}\item{scale}{either a logical value or a numeric vector of lengthequal to the number of columns of \code{x}.}}\value{For \code{scale.default}, the centered, scaled matrix. The numericcentering and scalings used (if any) are returned as attributes\code{"scaled:center"} and \code{"scaled:scale"}}\details{The value of \code{center} determines how column centering isperformed. If \code{center} is a numeric vector with length equal tothe number of columns of \code{x}, then each column of \code{x} hasthe corresponding value from \code{center} subtracted from it. If\code{center} is \code{TRUE} then centering is done by subtracting thecolumn means (omitting \code{NA}s) of \code{x} from theircorresponding columns, and if \code{center} is \code{FALSE}, nocentering is done.The value of \code{scale} determines how column scaling is performed(after centering). If \code{scale} is a numeric vector with lengthequal to the number of columns of \code{x}, then each column of\code{x} is divided by the corresponding value from \code{scale}. If\code{scale} is \code{TRUE} then scaling is done by dividing the(centered) columns of \code{x} by their standard deviations, and if\code{scale} is \code{FALSE}, no scaling is done.The standard deviation for a column is obtained by computing thesquare-root of the sum-of-squares of the non-missing values in thecolumn divided by the number of non-missing values minus one (whetheror not centering was done).}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth & Brooks/Cole.}\seealso{\code{\link{sweep}} which allows centering (and scaling) witharbitrary statistics.For working with the scale of a plot, see \code{\link{par}}.}\examples{require(stats)x <- matrix(1:10, ncol=2)(centered.x <- scale(x, scale=FALSE))cov(centered.scaled.x <- scale(x))# all 1}\keyword{array}