Chapter 8 Factors in R
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
args(factor)
## function (x = character(), levels, labels = levels, exclude = NA,
## ordered = is.ordered(x), nmax = NA)
## NULL
<- factor(c('Mobile', 'Tablet', 'Desktop'))
devices devices
## [1] Mobile Tablet Desktop
## Levels: Desktop Mobile Tablet
# number of levels
nlevels(devices)
## [1] 3
# levels
levels(devices)
## [1] "Desktop" "Mobile" "Tablet"