O'Reilly logo

R Programming Fundamentals by Kaelen Medeiros

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Factor Variables

We discussed variable types in Chapter 1, Introduction to R, but did not include factor variables because they're a special type of variable in R that you must often create yourself. In this section, we'll learn what a factor variable is, when to use a factor variable, how to create one, what the levels of a factor are, and how to change the levels.

A factor variable in R is an explicitly declared categorical variable, or one that defines different categories or levels. Some common examples of factor variables include a variable describing sex, month, or one designating low/medium/high.

Recall our discussion of variable classes and types from Chapter 1, Introduction to R. A factor variable will always be of class factor

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required