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
IMO the
fct_collapse()function should support usingNAas theother_levelargument.As of 0.5.0 one cannot use neither
NAtoNA_character_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