forcats (version 0.4.0)

fct_collapse: Collapse factor levels into manually defined groups

Description

Collapse factor levels into manually defined groups

Usage

fct_collapse(.f, ..., group_other = FALSE)

Arguments

.f

A factor (or character vector).

...

A series of named character vectors. The levels in each vector will be replaced with the name.

group_other

Replace all levels not named in ... with "Other"?

Examples

Run this code
# NOT RUN {
fct_count(gss_cat$partyid)

partyid2 <- fct_collapse(gss_cat$partyid,
  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")
)
fct_count(partyid2)
# }

Run the code above in your browser using DataCamp Workspace