tidyverse / forcats

🐈🐈🐈🐈: tools for working with categorical variables (factors)
https://forcats.tidyverse.org/
Other
553 stars 126 forks source link

Feature Request: Add handling of ordered factors to fct() #363

Open sambtalcott opened 2 months ago

sambtalcott commented 2 months ago

I would like to see the fct() function from forcats be extended to cover creating ordered factors. This could look like including ordered as an optional argument (as in base::factor()) and/or by creating an analogue function ord() that has the same default level-checking as fct().

In practice this would look like:

x <- c("A", "B", "A", "C", "A", "B", "D")
lvls <- c("F", "D", "C", "B", "A")

x <- fct(x, lvls, ordered = TRUE)

# and/or
x <- ord(x, lvls)

Thanks!