group_center: Group-mean center a variable

View source: R/group_center.R

group_centerR Documentation

Group-mean center a variable

Description

Also referred to as centering within cluster (or within context) or demeaning the variable. By default, uses na.rm = TRUE when computing group means.

Usage

group_center(x, grp)

Arguments

x

Variable to center (e.g., dataframe$varname).

grp

Cluster/grouping variable (e.g., dataframe$cluster).

Value

A vector of group-mean centered variables.

Examples

data(mtcars)
#create a group centered variable
mtcars$mpg.gpc <- group_center(mtcars$mpg, mtcars$cyl)

MLMusingR documentation built on Jan. 11, 2023, 5:09 p.m.