% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tabulation.R
\name{tab}
\alias{tab}
\alias{print.tidyaudit_tab}
\alias{as.data.frame.tidyaudit_tab}
\title{Tabulate Variables}
\usage{
tab(
  .data,
  ...,
  .wt = NULL,
  .sort = c("value_asc", "value_desc", "freq_desc", "freq_asc"),
  .cutoff = NULL,
  .na = c("include", "exclude", "only"),
  .display = c("count", "row_pct", "col_pct", "total_pct")
)

\method{print}{tidyaudit_tab}(x, ...)

\method{as.data.frame}{tidyaudit_tab}(x, row.names = NULL, optional = FALSE, ...)
}
\arguments{
\item{.data}{A data.frame or tibble.}

\item{...}{Additional arguments (currently unused).}

\item{.wt}{Optional unquoted column to use as frequency weights.
When supplied, frequencies are weighted sums instead of row counts.}

\item{.sort}{How to order the rows (and columns in two-way tables).
\code{"value_asc"} (default) sorts alphabetically (or by factor levels),
\code{"value_desc"} sorts in reverse, \code{"freq_desc"} sorts by frequency
descending, \code{"freq_asc"} sorts by frequency ascending.}

\item{.cutoff}{Controls how many values to display.
An integer >= 1 keeps the top-N values by frequency.
A number in (0, 1) keeps values that cumulatively account for that
proportion of the total. Remaining values are grouped under \code{"(Other)"}.
For two-way tables, the cutoff applies to the row variable only.}

\item{.na}{How to handle \code{NA} values. \code{"include"} (default) treats \code{NA} as a
category, \code{"exclude"} drops \code{NA} rows before tabulation, \code{"only"} shows
only \code{NA} rows.}

\item{.display}{Cell contents for two-way crosstabulations. One of
\code{"count"} (default), \code{"row_pct"}, \code{"col_pct"}, or \code{"total_pct"}.
Ignored for one-way tables.}

\item{x}{A \code{tidyaudit_tab} object.}

\item{row.names}{Passed to \code{\link[=as.data.frame]{as.data.frame()}}. Default \code{NULL}.}

\item{optional}{Passed to \code{\link[=as.data.frame]{as.data.frame()}}. Default \code{FALSE}.}
}
\value{
An S3 object of class \code{tidyaudit_tab}. Use \code{\link[=as.data.frame]{as.data.frame()}} to
extract the underlying table.
}
\description{
Produces one-way frequency tables or two-way crosstabulations. One variable
gives counts, percentages, and cumulative percentages; two variables give a
crosstabulation matrix with row/column totals.
}
\examples{
tab(mtcars, cyl)
tab(mtcars, cyl, .sort = "freq_desc")
tab(mtcars, cyl, gear)
tab(mtcars, cyl, gear, .display = "row_pct")
tab(mtcars, cyl, .wt = mpg)
tab(mtcars, cyl, .cutoff = 2)

}
\seealso{
Other data quality:
\code{\link[=audit_transform]{audit_transform()}},
\code{\link[=diagnose_nas]{diagnose_nas()}},
\code{\link[=diagnose_strings]{diagnose_strings()}},
\code{\link[=get_summary_table]{get_summary_table()}},
\code{\link[=summarize_column]{summarize_column()}}
}
\concept{data quality}
