Last chance! 50% off unlimited learning
Sale ends in
Compute group-mean centered variables. Usually used for HLM level-1 predictors.
group_mean_center(
data,
vars = setdiff(names(data), by),
by,
std = FALSE,
add.suffix = "",
add.group.mean = "_mean"
)
Data object.
Variable(s) to be centered.
Grouping variable.
Standardized or not. Default is FALSE
.
The suffix of the centered variable(s).
Default is ""
. You may set it to "_c"
, "_center"
, etc.
The suffix of the variable name(s) of group means.
Default is "_mean"
(see Examples).
A new data object containing the centered variable(s).
# NOT RUN {
d=data.table(x=1:9, g=rep(1:3, each=3))
d.c=group_mean_center(d, "x", by="g")
d.c
d.c=group_mean_center(d, "x", by="g", add.suffix="_c")
d.c
# }
Run the code above in your browser using DataLab