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.
9. Working with Factors: forcats
Get R Data Science Quick Reference: A Pocket Guide to APIs, Libraries, and Packages now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.