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

Description Usage Arguments Value Examples

View source: R/top_levels.R

Description

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

Usage

1
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

Returns 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

1

Example output

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test

                 as.factor(mtcars$hp)  n percent
                               52, 62  2  0.0625
 <<< Middle Group (18 categories) >>> 28  0.8750
                             264, 335  2  0.0625

janitor documentation built on Jan. 5, 2021, 9:07 a.m.