Skip to content

fct_collapse() should allow other_level = NA #291

@1pakch

Description

@1pakch

IMO the fct_collapse() function should support using NA as the other_level argument.

As of 0.5.0 one cannot use neither NA to NA_character_

library(purrr)
fac <- c(1, 2, 3, 4) %>% factor()
forcats::fct_collapse(fac, A = c('1', '2'), other_level = NA_character_)
forcats::fct_collapse(fac, A = c('1', '2'), other_level = NA)

and the workaround is quite awkward and too long

(
    fac
    %>% forcats::fct_collapse(A = c('1', '2'), other_level = 'NA')
    %>% na_if('NA')
    %>% fct_drop()
)

I'd be happy to look into it and make a PR.
This discussion might be relevant #101

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementhelp wanted ❤️we'd love your help!

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions