Chapter 8 Factors

8.1 Introduction

In this chapter, we will learn to:

  • create factors
  • order levels
  • specify labels
  • check levels
  • number of levels

Categorical or qualitative data in R is treated as data type factor.

8.2 Create Factors

## function (x = character(), levels, labels = levels, exclude = NA, 
##     ordered = is.ordered(x), nmax = NA) 
## NULL
## [1] Mobile  Tablet  Desktop
## Levels: Desktop Mobile Tablet
## [1] 3
## [1] "Desktop" "Mobile"  "Tablet"