March 2019
Beginner to intermediate
464 pages
10h 57m
English
Next, we are going to encode the three variables: job, housing, and marital. Since these variables do not have natural orders, we do not need to worry about which category gets encoded with which value. The simplest way to encode categorical variables with no orders in R is to use the factor function. Let's take a look at the following code:
df$job <- factor(df$job)df$housing <- factor(df$housing)df$marital <- factor(df$marital)
As you can see from this code, we are simply applying the factor function for these three variables, job, housing, and marital, and storing the encoded values back to the DataFrame, df. For the categorical variables that we have not discussed in this section, you can ...
Read now
Unlock full access