#' Tabulate frequency and relative frequency
#'
#' One-way and two-way tabulations of provided variables Speedboost via tidytable.
#' @param data The data frame to tabulate
#' @param tabvar The variables to tabulate
#' @param dropna If TRUE then drops NA values; if FALSE then includes NA values
#' @return A data frame with tabulation of counts and proportions.
#' @import tidytable
#' @examples
#' \dontrun{
#' kcf_tab(mtcars, c(vs)) # one-way tabulate
#' kcf_tab(mtcars, c(vs, am)) # two-way tabulate
#' }
kcf_tab <- function(data, tabvar, dropna = FALSE) {
data |>
{\(df) if (dropna == TRUE) tidytable::filter(df, tidytable::across(c({{ tabvar }}), ~ !is.na(.))) else df}() |>
tidytable::count({{ tabvar }}, name = "n") |>
tidytable::mutate(prop = n/sum(n))
}
.datatable.aware <- TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.