append_ns: Tastefully combine "label" and "n" columns

View source: R/append_ns.R

append_nsR Documentation

Tastefully combine "label" and "n" columns

Description

Uses the output from the y2clerk freqs() function and adds (n = ...) to the end of each label, based off the column "n". Useful for charts that require ns for all levels

Usage

append_ns(dataset, append_to = label, by_group_var = FALSE, newline = FALSE)

Arguments

dataset

A dataframe

append_to

(default: label). The variable to which you wish to add (n = ...)

by_group_var

(default: FALSE). If FALSE, takes ns by row. If TRUE, takes group ns by group_var levels. Set to TRUE if making a stacked bar chart

newline

(default: FALSE). If FALSE, (n = ...) comes after a space " ". If TRUE, it comes after a hard return

Examples


# by_group_var = FALSE
ToothGrowth %>%
  freqs(supp) %>%
  append_ns()

ToothGrowth %>%
  dplyr::group_by(supp) %>%
  freqs(dose) %>%
  append_ns(newline = TRUE)

# by_group_var = TRUE
ToothGrowth %>%
  dplyr::group_by(supp) %>%
  freqs(dose) %>%
  append_ns(
    append_to = group_var,
    by_group_var = TRUE
  )

y2analytics/y2clerk documentation built on March 26, 2024, 2:10 a.m.