Helpers for reordering factor levels (including moving specified levels to front, ordering by first appearance, reversing, and randomly shuffling), and tools for modifying factor levels (including collapsing rare levels into other, 'anonymising', and manually 'recoding').
forcats provides tools for categorical variables (forcats is an anagram of factors).
You can install the released version of forcats from CRAN with:
Or the development version from github with:
Change order of levels:
move specified level up front.
order by first appearance of each level.
order by summary of another value (same as
order by frequency.
randomly shuffle order of levels.
reverse order of levels.
shift levels to the left/right.
Change value of levels:
anonymise factor levels.
lump rarest (or most common) levels into "other".
manually recode levels.
Add new levels:
add new levels to a factor.
turn missing values into an explicit factor.
A few other helpers:
concatenate factors using union of levels.
count occurences of levels, optionally sorting by frequency.
ensure list of factors share the same levels.
compute from levels of factor.
drop levels without data (same as
finds union of levels from list of factors.
Minor fixes for R CMD check
Add package docs