powered by
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.
FALSE
The suffix of the centered variable(s). Default is "". You may set it to "_c", "_center", etc.
""
"_c"
"_center"
The suffix of the variable name(s) of group means. Default is "_mean" (see Examples).
"_mean"
A new data object containing the centered variable(s).
grand_mean_center
# 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