group_mean_center {bruceR}R Documentation

Group-mean centering.

Description

Compute group-mean centered variables. Usually used for HLM level-1 predictors.

Usage

group_mean_center(
  data,
  vars = setdiff(names(data), by),
  by,
  std = FALSE,
  add.suffix = "",
  add.group.mean = "_mean"
)

Arguments

data

Data object.

vars

Variable(s) to be centered.

by

Grouping variable.

std

Standardized or not. Default is FALSE.

add.suffix

The suffix of the centered variable(s). Default is "". You may set it to "_c", "_center", etc.

add.group.mean

The suffix of the variable name(s) of group means. Default is "_mean" (see Examples).

Value

A new data object containing the centered variable(s).

See Also

grand_mean_center

Examples

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


[Package bruceR version 0.8.0 Index]