Scale Columns of a Matrix

DESCRIPTION:
Centers and then scales the columns of a matrix. By default each column in the result has mean 0 and sample standard deviation 1.

USAGE:
scale(x, center=T, scale=T)

REQUIRED ARGUMENTS:
x:
matrix to be scaled. Missing values (NAs) are allowed.

OPTIONAL ARGUMENTS:
center:
control over the value subtracted from each column. If TRUE, the mean of (the non-missing data in) each column is subtracted from the column. If given as a vector of length ncol(x), this vector is used; i.e., center[j] is subtracted from column j. If FALSE, no centering is done.
scale:
control over the value divided into each column to scale it. If TRUE each column (after centering) is divided by the square root of sum-of-squares (after centering) over n-1, where n is the number of non-missing values. If given as a vector of length ncol(x), column j is divided by scale[j]. If FALSE, no scaling is done.

VALUE:
matrix like x with optional centering and scaling.

DETAILS:
scale takes as an argument x (matrix) and returns a similar matrix whose columns take elements corresponding to the center (mean), and scale (standard deviation). If center and scale are not specified, the default values will be 0 and 1, respectively.

SEE ALSO:
sweep , apply , var , mad .

EXAMPLES:
scale(x) #scale to correlation (0 mean, 1 std dev)
scale(x, center=apply(x,2,median), scale=FALSE)
    #remove column medians, do not scale