sum_tab: Create a Frequency Table for a Variable in a Data Frame

View source: R/sum_tab.R

sum_tabR Documentation

Create a Frequency Table for a Variable in a Data Frame

Description

sum_tab takes a built in function (table) and turns it into something that can be integrated into a sequence of pipes. As with sum_lm, this is useful for when you want to see many tables at once, or put a few tables into a bigger table. Writing this was surprisingly complicated – it uses enquo() to capture the unquoted variable name and !! to unquote it within the function.

Usage

sum_tab(data, var_name)

Arguments

data

A data frame or tibble.

var_name

The name of the variable/column to generate the frequency table.

Value

A table showing the frequency of each unique value in the specified variable. #'

Examples

# simple example: entire dataset
PaluckMetaSOP::sv_data |> sum_tab(behavior_type)
## Not run: 
# example with split and apply to many subsets
library(purrr)
PaluckMetaSOP::sv_data |> split(~study_design) |>
map(~ sum_tab(., behavior_type)) |> bind_rows(.id = "study_design")

## End(Not run)

setgree/PrejMetaFunctions documentation built on May 8, 2024, 6:38 p.m.