Skip to content

fct_lump all with count above/below threshold #142

Closed

Description

@RoyalTS

It would be great if fct_lump() had an additional mode that lumped factor levels not based on the final number of factor levels desired (n) or the proportion of the data that accrues to the level (prop) but based on the raw count for the level (call it count?).

Stealing the example data from #43:

N <- 5
M <- 2 ** N
exp_factor <- factor(rep(1:(N + M), c(2 ** (N:1), rep(1, M))))
table(exp_factor)
## exp_factor
##  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 
## 32 16  8  4  2  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1 
## 26 27 28 29 30 31 32 33 34 35 36 37 
##  1  1  1  1  1  1  1  1  1  1  1  1

Desired behavior: forcats::fct_lump(exp_factor, count = 1) would retain only the factor levels 1:5 and Other.

Activity

  1. AshesITR commented on Nov 17, 2018

    @AshesITR

    That's a good idea. Maybe naming the argument min_count with comparison >= makes the functionality clearer...

  2. hadley commented on Jan 4, 2019

    @hadley
    Member

    I think this is a reasonable request, but my main concern is making fct_lump() too complicated. It might be time to start spinning out fct_lump_prop() etc.

  3. added
    featurea feature request or enhancement
    tidy-dev-day 🤓Tidyverse Developer Day rstd.io/tidy-dev-day
    on Jan 4, 2019
  4. robinsones commented on Jan 19, 2019

    @robinsones
    Contributor

    👋 I'll try it

  5. added a commit that references this issue on Jan 23, 2019
    3f789ee
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

    featurea feature request or enhancementtidy-dev-day 🤓Tidyverse Developer Day rstd.io/tidy-dev-day

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions