Learn R Programming

summarytabl (version 0.2.1)

cat_tbl: 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)

Value

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

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.

Author

Ama Nyame-Mensah

Examples

Run this code
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)

Run the code above in your browser using DataLab