tidyverse / forcats

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

Feature Request: fct_trim() #358

Open sebneus opened 10 months ago

sebneus commented 10 months 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!