Get a frequency table of a factor variable, grouped into categories by level.
top_levels(input_vec, n = 2, show_na = FALSE)
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
.)
the factor variable to tabulate.
number of levels to include in top and bottom groups
should cases where the variable is NA be shown?
top_levels(as.factor(mtcars$hp), 2)
Run the code above in your browser using DataLab