summarize_group_cols: Summarize group columns

View source: R/summarize_group_cols.R

summarize_group_colsR Documentation

Summarize group columns

Description

\Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}

Get the following summary statistics for each group column:

  1. Number of groups

  2. Mean, median, std., IQR, min, and max number of rows per group.

The output can be given in either long (default) or wide format.

Usage

summarize_group_cols(data, group_cols, long = TRUE)

Arguments

data

data.frame with one or more group columns (factors) to summarize.

group_cols

Names of columns to summarize. These columns must be factors in `data`.

long

Whether the output should be in long or wide format.

Value

Data frame (tibble) with summary statistics for each column in `group_cols`.

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

See Also

Other summarization functions: ranked_balances(), summarize_balances()

Examples

# Attach packages
library(groupdata2)

# Create data frame
df <- data.frame(
  "some_var" = runif(25),
  "grp_1" = factor(sample(1:5, size = 25, replace=TRUE)),
  "grp_2" = factor(sample(1:8, size = 25, replace=TRUE)),
  "grp_3" = factor(sample(LETTERS[1:3], size = 25, replace=TRUE)),
  "grp_4" = factor(sample(LETTERS[1:12], size = 25, replace=TRUE))
)

# Summarize the group columns (long format)
summarize_group_cols(
  data = df,
  group_cols = paste0("grp_", 1:4),
  long = TRUE
 )

# Summarize the group columns (wide format)
summarize_group_cols(
  data = df,
  group_cols = paste0("grp_", 1:4),
  long = FALSE
 )

groupdata2 documentation built on July 9, 2023, 6:46 p.m.