Factor(...levels = ... , order = TRUE) in forcats



I was wondering if there was an equivalent in forcats for the following example
factor(..., level = ..., ordered = TRUE)
and results.

a <- tibble(Id = 1:90, quality = rep(c("none", "poor", "fair", "average", "good", "excellent"), 15))
a$quality <- factor(a$quality, levels = c("none", "poor", "fair", "average", "good", "excellent"), ordered = TRUE)
[1] none poor fair average good excellent
Levels: none < poor < fair < average < good < excellent

This is important in the case of doing regression with ordinal categorical variable (likert scale, or bad/average/good, etc.)


I think of forcats as a tool to help you get your R factors the way you desire. So if you have a nice way to get what you desire with base-R or something else, just use that.

But also forcats does have the following tools: