Skip to content
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_lump_prop() errors with weights and unused levels #292

Closed
sam-crawley opened this issue Dec 10, 2021 · 1 comment · Fixed by #335
Closed

fct_lump_prop() errors with weights and unused levels #292

sam-crawley opened this issue Dec 10, 2021 · 1 comment · Fixed by #335
Labels
bug an unexpected problem or unintended behavior help wanted ❤️ we'd love your help!
Milestone

Comments

@sam-crawley
Copy link

When calling fct_lump_prop with weights, and with a factor that has unused levels, I get the error:

Error in if (prop > 0 && sum(prop_n <= prop) <= 1) { :
missing value where TRUE/FALSE needed

Reprex:

f <- factor(c("a", "b", "c"), levels = c("a", "b", "c", "d"))
f <- fct_lump_prop(f, prop = 0.02,  w = c(1,1,1))

Calling fct_drop() beforehand prevents the error.

@hadley
Copy link
Member

hadley commented Mar 2, 2022

Reprex:

library(forcats)
f <- factor(c("a", "a", "b", "c"), levels = c("a", "b", "c", "d"))

fct_lump_prop(f, prop = 0.25)
#> [1] a     a     Other Other
#> Levels: a Other
fct_lump_prop(f, prop = 0.25, w = rep(1, 4))
#> Error in if (prop > 0 && sum(prop_n <= prop) <= 1) {: missing value where TRUE/FALSE needed

Created on 2022-03-02 by the reprex package (v2.0.1)

@hadley hadley added bug an unexpected problem or unintended behavior help wanted ❤️ we'd love your help! labels Mar 2, 2022
@hadley hadley added this to the v1.0.0 milestone Jan 3, 2023
@hadley hadley changed the title Error in fct_lump_prop with weights and unused levels fct_lump_prop() errors with weights and unused levels Jan 3, 2023
hadley added a commit that referenced this issue Jan 4, 2023
hadley added a commit that referenced this issue Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior help wanted ❤️ we'd love your help!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants