Reorder the factors of a categorical variable either manually or frequency
Usage
reorderLevels(
.data,
var,
new_levels = NULL,
freq = FALSE,
name = sprintf("%s.reord", var)
)
Value
original dataframe containing a new column of the reordered
categorical variable with tidyverse code attached
Arguments
.data
a dataframe to reorder
var
a categorical variable to reorder
new_levels
a character vector of the new factor order.
Only specify if freq = FALSE
freq
logical, If freq = FALSE (default),
will manually reorder using new_levels.
If freq = TRUE, will reorder
based of descending frequency of the factor levels