center | R Documentation |
Performs a grand-mean centering of data.
center(x, ...)
centre(x, ...)
## S3 method for class 'numeric'
center(
x,
robust = FALSE,
weights = NULL,
reference = NULL,
center = NULL,
verbose = TRUE,
...
)
## S3 method for class 'data.frame'
center(
x,
select = NULL,
exclude = NULL,
robust = FALSE,
weights = NULL,
reference = NULL,
center = NULL,
force = FALSE,
remove_na = c("none", "selected", "all"),
append = FALSE,
ignore_case = FALSE,
verbose = TRUE,
regex = FALSE,
...
)
x |
A (grouped) data frame, a (numeric or character) vector or a factor. |
... |
Currently not used. |
robust |
Logical, if |
weights |
Can be
|
reference |
A data frame or variable from which the centrality and deviation will be computed instead of from the input variable. Useful for standardizing a subset or new data according to another data frame. |
center |
Numeric value, which can be used as alternative to
|
verbose |
Toggle warnings and messages. |
select |
Variables that will be included when performing the required tasks. Can be either
If |
exclude |
See |
force |
Logical, if |
remove_na |
How should missing values ( |
append |
Logical or string. If |
ignore_case |
Logical, if |
regex |
Logical, if |
The centered variables.
select
argumentFor most functions that have a select
argument (including this function),
the complete input data frame is returned, even when select
only selects
a range of variables. That is, the function is only applied to those variables
that have a match in select
, while all other variables remain unchanged.
In other words: for this function, select
will not omit any non-included
variables, so that the returned data frame will include all variables
from the input data frame.
Difference between centering and standardizing: Standardized variables are computed by subtracting the mean of the variable and then dividing it by the standard deviation, while centering variables involves only the subtraction.
If centering within-clusters (instead of grand-mean centering)
is required, see demean()
. For standardizing, see standardize()
, and
makepredictcall.dw_transformer()
for use in model formulas.
data(iris)
# entire data frame or a vector
head(iris$Sepal.Width)
head(center(iris$Sepal.Width))
head(center(iris))
head(center(iris, force = TRUE))
# only the selected columns from a data frame
center(anscombe, select = c("x1", "x3"))
center(anscombe, exclude = c("x1", "x3"))
# centering with reference center and scale
d <- data.frame(
a = c(-2, -1, 0, 1, 2),
b = c(3, 4, 5, 6, 7)
)
# default centering at mean
center(d)
# centering, using 0 as mean
center(d, center = 0)
# centering, using -5 as mean
center(d, center = -5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.