Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

center

Centering (Grand-Mean Centering)


Description

Performs a grand-mean centering of data.

Usage

center(x, ...)

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

## S3 method for class '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

data(iris)
head(iris$Sepal.Width)
head(center(iris$Sepal.Width))
head(center(iris))
head(center(iris, force = TRUE))

parameters

Processing of Model Parameters

v0.13.0
GPL-3
Authors
Daniel Lüdecke [aut, cre] (<https://orcid.org/0000-0002-8895-3206>, @strengejacke), Dominique Makowski [aut] (<https://orcid.org/0000-0001-5375-9967>), Mattan S. Ben-Shachar [aut] (<https://orcid.org/0000-0002-4287-4801>), Indrajeet Patil [aut] (<https://orcid.org/0000-0003-1995-6531>, @patilindrajeets), Søren Højsgaard [aut], Zen J. Lau [ctb], Vincent Arel-Bundock [ctb] (<https://orcid.org/0000-0003-1995-6531>, @vincentab), Jeffrey Girard [ctb] (<https://orcid.org/0000-0002-7359-3746>, @jeffreymgirard)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.