reorder_levels | R Documentation |
Reorder the levels of a categorical variable either manually or automatically
reorder_levels(
data,
var,
new_levels = NULL,
auto = c("freq", "order", "seq"),
name = NULL
)
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 |
original dataframe containing a new column of the reordered categorical variable with tidyverse code attached
Zhaoming Su
code
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.