reorderLevels {iNZightTools} | R Documentation |
Reorder the factors of a categorical variable either manually or frequency
reorderLevels(
.data,
var,
new_levels = NULL,
freq = FALSE,
name = sprintf("%s.reord", var)
)
.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 |
logical, If |
name |
name for the new variable |
original dataframe containing a new column of the reordered categorical variable with tidyverse code attached
Owen Jin
reordered <- reorderLevels(iris, var = "Species",
new_levels = c("versicolor", "virginica", "setosa"))
cat(code(reordered))
head(reordered)