Skip to content

fct_lump_prop() errors with weights and unused levels #292

Closed

Description

@sam-crawley

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.

Activity

  1. hadley commented on Mar 2, 2022

    @hadley
    Member

    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)

  2. added
    bugan unexpected problem or unintended behavior
    on Mar 2, 2022
  3. added this to the v1.0.0 milestone on Jan 3, 2023
  4. changed the title [-]Error in fct_lump_prop with weights and unused levels[/-] [+]`fct_lump_prop()` errors with weights and unused levels[/+] on Jan 3, 2023
  5. added a commit that references this issue on Jan 4, 2023
    ee63353
  6. added a commit that references this issue on Jan 5, 2023
    42fd258
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorhelp wanted ❤️we'd love your help!

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions