top_levels: Generate a frequency table of a factor grouped into top-n,...

View source: R/top_levels.R

top_levelsR Documentation

Generate a frequency table of a factor grouped into top-n, bottom-n, and all other levels.

Description

Get a frequency table of a factor variable, grouped into categories by level.

Usage

top_levels(input_vec, n = 2, show_na = FALSE)

Arguments

input_vec

The factor variable to tabulate.

n

Number of levels to include in top and bottom groups

show_na

Should cases where the variable is NA be shown?

Value

A data.frame (actually a tbl_df) with the frequencies of the grouped, tabulated variable. Includes counts and percentages, and valid percentages (calculated omitting NA values, if present in the vector and show_na = TRUE.)

Examples

top_levels(as.factor(mtcars$hp), 2)

sfirke/janitor documentation built on Feb. 6, 2024, 12:37 p.m.