tidyverse / forcats

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

Feature Request: fct_trim() #358

Closed sebneus closed 1 month ago

sebneus commented 1 year ago

Hi

I search for a function which trims the factor levels. It should basically work like fct_drop() but not inbetween used levels:

Example:

factor(c("b", "e"), level = c("a", "b", "c", "d", "e", "f" )) |> 
  forcats::fct_drop() |> 
  levels()
#> [1] "b" "e"

factor(c("b", "e"), level = c("a", "b", "c", "d", "e", "f" )) |> 
  forcats::fct_trim() |> 
  levels()
#> [1] "b" "c" "d" "e"

Regards and thank you for the good job!

hadley commented 1 month ago

Thanks for filing this issue! Unfortunately, I think it's a bit too specialised for forcats: developing good software requires relentless focus, which means that we have to say no to many good ideas. Even though I'm closing this issue, I really appreciate the feedback, and hope you'll continue to contribute in the future 😄