The cylinders variable in the Auto dataset is stored as a numeric vector, so R has treated it as quantitative. We can check this with the class() function. First we install the package where we can find this dataset, load the package and load the dataset.

install.packages('ISLR2')
library(ISLR2)
data(Auto)
class(Auto$cylinders)
[1] "integer"

However, since there are only a small number of possible values for cylinders, one may prefer to treat it as a qualitative variable. The as.factor() function converts quantitative variables into qualitative variables.

> Auto$cylinders = as.factor(Auto$cylinders)
> class(Auto$cylinders)
[1] "factor"

Right now this might seem unnecessary, but changing qualitative variables into factors will prove useful later on.

Question