Tools for Working with Categorical Variables (Factors)

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').


CRAN_Status_Badge](https://cran.r-project.org/package=forcats)

forcats provides tools for categorical variables (forcats is an anagram of factors).

You can install the released version of forcats from CRAN with:

install.packages("forcats")

Or the development version from github with:

# install.packages("devtools")
devtools::install_github("hadley/forcats")

Change order of levels:

Change value of levels:

Add new levels:

A few other helpers:

  • fct_c(): concatenate factors using union of levels.

  • fct_count():
    count occurences of levels, optionally sorting by frequency.

  • fct_unify():
    ensure list of factors share the same levels.

  • fct_unique(): compute from levels of factor.

  • fct_drop(): drop levels without data (same as base::droplevels()).

  • lvls_union(): finds union of levels from list of factors.

News

forcats 0.1.1

  • Minor fixes for R CMD check

  • Add package docs

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("forcats")

0.2.0 by Hadley Wickham, 2 months ago


http://forcats.tidyverse.org, https://github.com/tidyverse/forcats


Report a bug at https://github.com/tidyverse/forcats/issues


Browse source code at https://github.com/cran/forcats


Authors: Hadley Wickham [aut, cre], RStudio [cph, fnd]


Documentation:   PDF Manual  


GPL-3 license


Imports tibble, magrittr

Suggests ggplot2, testthat, covr


Imported by tidyverse.

Suggested by nzelect, tidyquant.


See at CRAN