compare_pairs: Compare pairs of categorical variables

View source: R/dplyr.R

compare_pairsR Documentation

Compare pairs of categorical variables

Description

Compare pairs of categorical variables

Usage

compare_pairs(data, levels, values, f = `-`)

Arguments

data

a dataframe

levels

a column with a categorical variable. All pairs of values in levels will be compared.

values

a column with values to compare.

f

comparison function to apply to values in each pair. Defaults to - to compute the pairwise differences.

Value

a dataframe with pairwise comparisons

Examples

to_compare <- nlme::Machines %>%
  dplyr::group_by(Worker) %>%
  dplyr::summarise(avg_score = mean(score)) %>%
  print()

to_compare %>%
  compare_pairs(Worker, avg_score) %>%
  dplyr::rename(difference = value) %>%
  dplyr::mutate_if(is.numeric, round, 1)

tjmahr/tjmisc documentation built on Feb. 8, 2023, 12:21 p.m.