-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fct_collapse()
should allow other_level = NA
#291
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
Reprex: library(forcats)
x <- factor(1:4)
fct_collapse(x, A = c("1", "2"), other_level = "other")
#> [1] A A other other
#> Levels: A other
fct_collapse(x, A = c("1", "2"), other_level = NA)
#> Error in new[[other_level]] <- levels[!levels %in% levs]: attempt to select less than one element in integerOneIndex Created on 2022-03-02 by the reprex package (v2.0.1) |
fct_collapse()
should allow other_level = NA
If we support this, also need to make sure it works in
|
Hmmm, rather surprisingly you can already do what you want with this: library(forcats)
x <- factor(1:4)
fct_collapse(x, A = c("1", "2"), other_level = "NULL")
#> [1] A A <NA> <NA>
#> Levels: A Created on 2023-01-03 with reprex v2.0.2 |
IMO the
fct_collapse()
function should support usingNA
as theother_level
argument.As of 0.5.0 one cannot use neither
NA
toNA_character_
and the workaround is quite awkward and too long
I'd be happy to look into it and make a PR.
This discussion might be relevant #101
The text was updated successfully, but these errors were encountered: