reorder_levels {iNZightTools} | R Documentation |
Reorder the levels of a categorical variable
Description
Reorder the levels of a categorical variable either manually or automatically
Usage
reorder_levels(
data,
var,
new_levels = NULL,
auto = c("freq", "order", "seq"),
name = NULL
)
Arguments
data |
a dataframe to reorder |
var |
a categorical variable to reorder |
new_levels |
a character vector of the new factor order;
overrides |
auto |
only meaningful if |
name |
name for the new variable |
Value
original dataframe containing a new column of the reordered categorical variable with tidyverse code attached
Author(s)
Zhaoming Su
See Also
Examples
reordered <- reorder_levels(iris,
var = "Species",
new_levels = c("versicolor", "virginica", "setosa")
)
cat(code(reordered))
head(reordered)
reordered <- reorder_levels(iris,
var = "Species",
auto = "freq"
)
cat(code(reordered))
head(reordered)
[Package iNZightTools version 2.0.1 Index]