I'm trying to collapse a long list of levels for a factor variable, and for neatness's sake would rather create a named list outside of my munging pipe, but I can't seem to get this to work with fct_collapse even though there's nothing in the code that would suggest that it shouldn't.
library(tidyverse)
library(forcats)
data(gss_cat)
party_change <- lst(
missing = c("No answer", "Don't know"),
other = "Other party",
rep = c("Strong republican", "Not str republican"),
ind = c("Ind,near rep", "Independent", "Ind,near dem"),
dem = c("Not str democrat", "Strong democrat")
)
partyid2 <- fct_collapse(gss_cat$partyid, party_change)
fct_count(partyid2)
# A tibble: 1 x 2
f n
<fct> <int>
1 "" 21483
Any suggestions for how I might be able to get this to work? TIA!