Learn R Programming

MLMusingR (version 0.3.2)

group_center: 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)

Value

A vector of group-mean centered variables.

Arguments

x

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

grp

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

Examples

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

Run the code above in your browser using DataLab