Learn R Programming

parameters (version 0.14.0)

center: Centering (Grand-Mean Centering)

Description

Performs a grand-mean centering of data.

Usage

center(x, ...)

# S3 method for numeric center(x, weights = NULL, robust = FALSE, verbose = TRUE, ...)

# S3 method for data.frame center( x, select = NULL, exclude = NULL, weights = NULL, robust = FALSE, force = FALSE, append = FALSE, suffix = "_c", verbose = TRUE, ... )

Arguments

x

A data frame, a (numeric or character) vector or a factor.

...

Currently not used.

weights

Can be NULL (for no weighting), or:

  • For data frames: a numeric vector of weights, or a character of the name of a column in the data.frame that contains the weights.

  • For numeric vectors: a numeric vector of weights.

robust

Logical, if TRUE, centering is done by subtracting the median from the variables. If FALSE, variables are centered by subtracting the mean.

verbose

Toggle warnings and messages.

select

Character vector of column names. If NULL (the default), all variables will be selected.

exclude

Character vector of column names to be excluded from selection.

force

Logical, if TRUE, forces centering of factors as well. Factors are converted to numerical values, with the lowest level being the value 1 (unless the factor has numeric levels, which are converted to the corresponding numeric value).

append

Logical, if TRUE and x is a data frame, standardized variables will be added as additional columns; if FALSE, existing variables are overwritten.

suffix

Character value, will be appended to variable (column) names of x, if x is a data frame and append = TRUE.

Value

The centered variables.

See Also

If centering within-clusters (instead of grand-mean centering) is required, see demean.

Examples

Run this code
# NOT RUN {
data(iris)
head(iris$Sepal.Width)
head(center(iris$Sepal.Width))
head(center(iris))
head(center(iris, force = TRUE))
# }

Run the code above in your browser using DataLab