Forcats
Reference of datar.forcats
Reference map of r-tidyverse-forcats can be found here.
Legend:
| Sample | Status |
|---|---|
| normal | API that is regularly ported |
| API that is not ported, or not an API originally | |
| bold | API that is unique in datar |
| italic | Working in process |
Change order of levels
| API | Description | Notebook example |
|---|---|---|
| fct_relevel() | Reorder factor levels by hand | |
| fct_inorder() fct_infreq() fct_inseq() | Reorder factor levels by first appearance, frequency, or numeric order | |
| fct_reorder() fct_reorder2() last2() first2() | Reorder factor levels by sorting along another variable | |
| fct_shuffle() | Randomly permute factor levels | |
| fct_rev() | Reverse order of factor levels | |
| fct_shift() | Shift factor levels to left or right, wrapping around at end |
Change value of levels
| API | Description | Notebook example |
|---|---|---|
| fct_anon() | Anonymise factor levels | |
| fct_collapse() | Collapse factor levels into manually defined groups | |
| fct_lump() fct_lump_min() fct_lump_prop() fct_lump_n() fct_lump_lowfreq() | Lump together actor levels into "other" | |
| fct_other() | Replace levels with "other" | |
| fct_recode() | Change factor levels by hand | |
| fct_relabel() | Automatically relabel factor levels, collapse as necessary |
Add/remove levels
| API | Description | Notebook example |
|---|---|---|
| fct_expand() | Add additional levels to a factor | |
| fct_explicit_na() | Make missing values explicit | |
| fct_drop() | Drop unused levels | |
| fct_unify() | Unify the levels in a list of factors |
Combine multiple factors
| API | Description | Notebook example |
|---|---|---|
| fct_c() | Concatenate factors, combining levels | |
| fct_cross() | Combine levels from two or more factors to create a new factor |
Other helpers
| API | Description | Notebook example |
|---|---|---|
| as_factor() | Convert input to a factor | |
| fct_count() | Count entries in a factor | |
| fct_match() | Test for presence of levels in a factor | |
| fct_unique() | Unique values of a factor | |
| lvls_reorder() lvls_revalue() lvls_expand() | Low-level functions for manipulating levels | |
| lvls_union() | Find all levels in a list of factors |