tidyverse / forcats

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

Feature Request: Allow Increasing Order in `fct_infreq` #365

Open drfloren opened 2 months ago

drfloren commented 2 months ago

Current implementation has fct_infreq locked in descending order. Request is to passthrough an argument to order allowing both directions.

Current version is:

fct_infreq <- function(f, w = NULL, ordered = NA) {
  f <- check_factor(f)
  w <- compute_weights(f, w)
  check_bool(ordered, allow_na = TRUE)

  lvls_reorder(f, order(w, decreasing = TRUE), ordered = ordered)
}

Example with update would be something like:

fct_infreq <- function(f, w = NULL, ordered = NA, desc = TRUE) {
  f <- check_factor(f)
  w <- compute_weights(f, w)
  check_bool(ordered, allow_na = TRUE)

  lvls_reorder(f, order(w, decreasing = desc), ordered = ordered)
}