\Header{scale}{Scaling and Centering of Matrix-like Objects}
\methalias{scale.default}{scale}
\keyword{array}{scale}
\begin{Description}\relax
\code{scale} is generic function whose default method centers and/or
scales the columns of a numeric matrix.
\end{Description}
\begin{Usage}
\begin{verbatim}
scale(x, center = TRUE, scale = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a numeric matrix(like object).
\item[\code{center}] either a logical value or a numeric vector of length
equal to the number of columns of \code{x}.
\item[\code{scale}] either a logical value or a numeric vector of length
equal to the number of columns of \code{x}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The value of \code{center} determines how column centering is
performed.
If \code{center} is a numeric vector with length equal to the number
of columns of \code{x}, then each column of \code{x} has the
corresponding value from \code{center} subtracted from it.
If \code{center} is \code{TRUE} then centering is done by subtracting
the column means (omitting \code{NA}s) of \code{x} from their
corresponding columns, and if \code{center} is \code{FALSE},
no centering is done.

The value of \code{scale} determines how column scaling is performed
(after centering).
If \code{scale} is a numeric vector with length equal 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 root-mean-square, and if
\code{scale} is \code{FALSE}, no scaling is done.

The root-mean-square for a column is obtained by computing the
square-root of the sum-of-squares of the non-missing values in the
column divided by the number of non-missing values minus one.
\end{Details}
\begin{Value}
For \code{scale.default}, the centered, scaled matrix. The numeric
centering and scalings used (if any) are returned as attributes
\code{"scaled:center"} and \code{"scaled:scale"}
\end{Value}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\Link{sweep}} which allows centering (and scaling) with
arbitrary statistics.

For working with the scale of a plot, see \code{\Link{par}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
require(stats)
x <- matrix(1:10, nc=2)
(centered.x <- scale(x, scale=FALSE))
cov(centered.scaled.x <- scale(x))# all 1
\end{ExampleCode}
\end{Examples}

