WG_centre: Carry out within-group centring.

Description Usage Arguments Value Examples

Description

Calculate within-group effects based on methods of van de Pol and Wright.

Usage

1
WG_centre(data, Variable, Group)

Arguments

data

Dataset in which within-group centring will be carried out. N.B. First argument makes this function compatible with dplyr piping.

Variable

An unquoted column name. The name of variable column on which centring will occur.

Group

An unquoted column name. The name of grouping column.

Value

A tibble with two new columns containing within group mean and deviance.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(dplyr)

dummy_dat <- tibble(group = rep(LETTERS[1:4], 20), value = runif(80, 0, 10))

#Stand alone function
WG_centre(dummy_dat, value, group)

#Inside dplyr pipe
dummy_dat %>%
  #Merge two factor levels
  rowwise() %>%
  mutate(group = ifelse(group == "B", "A", group)) %>%
  WG_centre(value, group)

LiamDBailey/MyFuncs documentation built on June 5, 2019, 5:10 p.m.