ID EN
Miscellaneous

scale

R Base 3.6.2

scale is generic function whose default method centers and/or scales the columns of a numeric matrix.

Syntax

R
scale(x, center = TRUE, scale = TRUE)

Arguments

Parameter Description
x a numeric matrix(like object).
center either a logical value or numeric-alike vector of length equal to the number of columns of x, where ‘numeric-alike’ means that as.numeric(.) will be applied successfully if is.numeric(.) is not true.
scale either a logical value or a numeric-alike vector of length equal to the number of columns of x.

Return Value

For scale.default, the centered, scaled matrix. The numeric centering and scalings used (if any) are returned as attributes "scaled:center" and "scaled:scale"

Details

The value of center determines how column centering is performed. If center is a numeric-alike vector with length equal to the number of columns of x, then each column of x has the corresponding value from center subtracted from it. If center is TRUE then centering is done by subtracting the column means (omitting NAs) of x from their corresponding columns, and if center is FALSE, no centering is done. The value of scale determines how column scaling is performed (after centering). If scale is a numeric-alike vector with length equal to the number of columns of x, then each column of x is divided by the corresponding value from scale. If scale is TRUE then scaling is done by dividing the (centered) columns of x by their standard deviations if center is TRUE, and the root mean square otherw

Examples

Example
R
# NOT RUN {
require(stats)
x <- matrix(1:10, ncol = 2)
(centered.x <- scale(x, scale = FALSE))
cov(centered.scaled.x <- scale(x)) # all 1
# }

See Also

sweep which allows centering (and scaling) with arbitrary statistics. For working with the scale of a plot see par.