cat_tbl: Summarize a categorical variable

View source: R/cat_tbl.R

cat_tblR Documentation

Summarize a categorical variable

Description

cat_tbl() summarizes nominal or categorical variables, returning frequency counts and percentages.

Usage

cat_tbl(data, var, na.rm = FALSE, only = NULL, ignore = NULL)

Arguments

data

A data frame.

var

A character string of the name of a variable in data containing categorical data.

na.rm

A logical value indicating whether missing values should be removed before calculations. Default is FALSE.

only

A character string or vector of character strings of the types of summary data to return. Default is NULL, which returns both counts and percentages. To return only counts or percentages, use count or percent, respectively.

ignore

An optional vector that contains values to exclude from var. Default is NULL, which retains all values.

Value

A tibble showing the count and percentage of each category in var

Author(s)

Ama Nyame-Mensah

Examples

cat_tbl(data = nlsy, var = "gender")

cat_tbl(data = nlsy, var = "race", only = "count")

cat_tbl(data = nlsy,
        var = "race",
        ignore = "Hispanic",
        only = "percent",
        na.rm = TRUE)


summarytabl documentation built on Nov. 6, 2025, 5:07 p.m.