group_mean_center: Returns data including group means and group mean centered...

View source: R/group_mean_center.R

group_mean_centerR Documentation

Returns data including group means and group mean centered variables

Description

Returns data including group means and group mean centered variables

Usage

group_mean_center(data, group.var, vars, grand.init = FALSE)

Arguments

data

Data frame of individual observations across multiple groups.

group.var

Character string name of the grouping variable.

vars

Vector of numeric variable names to be centered.

grand.init

Is initial grand mean centering to each variable applied (default FALSE)?

Value

Data frame with group means and variables centered around group means.

Examples

set.seed(234)
n1 <- 3 # groups
n2 <- 3 # observations per groups
dat <- data.frame(
  group = rep(c(LETTERS[1:n1]), each = n2),
  x1 = sample(1:5, n1 * n2, replace = TRUE),
  x2 = sample(1:5, n1 * n2, replace = TRUE),
  x3 = sample(1:5, n1 * n2, replace = TRUE)
)

group_mean_center(
  data = dat, group.var = "group",
  vars = c("x1", "x2", "x3")
)

vjilmari/vjihelpers documentation built on May 23, 2022, 6:43 p.m.