R/tab_function.R

Defines functions tab

Documented in tab

#' Tab(ulate), similar to Stata (orders by x, or x,y). Requires data.table.
#' Data argument defaults to dt, for easy usage tab("x").
#' @param x Variable to be tabulated
#' @param y Optional second variable
#' @param df the dataframe
#' @keywords tab, table, tabulate
#' @importFrom data.table .N
#' @export
#' @return Table of (N) cases ordered by x or x, y.
#' @examples
#' tab()
tab <- function(x = NULL, y = NULL, df = dt) {
    df[, .N, keyby = c(x, y)]
}
edvinsyk/etools documentation built on Jan. 8, 2022, 1:31 p.m.