© Thomas Mailund 2019
Thomas MailundR Data Science Quick Referencehttps://doi.org/10.1007/978-1-4842-4894-2_9

9. Working with Factors: forcats

Thomas Mailund1 
Aarhus, Denmark

If you work with categorical data, you can often represent the categories by strings. Strings have some drawbacks, however. For example, a spelling mistake can easily go undiscovered. If you want your categories ordered, then the lexicographical order on strings will not always be the order you need. As an alternative to strings for categories is factors. In this chapter, we look at the functionality that the forcats package provides for creating and manipulating factors.

The package is loaded when you import tidyverse,
but you can also load it explicitly ...

Get R Data Science Quick Reference: A Pocket Guide to APIs, Libraries, and Packages now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.