R/sum_tab.R

Defines functions sum_tab

Documented in sum_tab

#' Create a Frequency Table for a Variable in a Data Frame
#'
#' This function generates a frequency table for a specific variable in a dataset.
#'
#' It uses enquo() to capture the unquoted variable name and !! to unquote it
#' within the function.
#' @param data A data frame or tibble.
#' @param var_name The name of the variable/column to generate the frequency table.
#'
#' @return A table showing the frequency of each unique value in the specified variable.
#'#'
#' @importFrom dplyr pull
#' @importFrom rlang !! enquo
#' @export

sum_tab <- function(data, var_name) {
  var_name <- enquo(var_name)
  freq_table <- table(data |> pull(!!var_name))
  return(freq_table)
}
setgree/PrejMetaFunctions documentation built on April 28, 2024, 9:29 a.m.