I am trying to transform all my categorical variables into numerical ones, it seems easy with the logical variables (Yes or No), but it is harder for me with the categorical variables with more than 2 options. ¿How can I change the BusinessTravel variable which has 3 options ("Non-Travel", "Rarely_Travel", and "Frequently_Travel") to a numerical variable (0, 1, and 2)?
#---- load the dataset ----#
library(readr)
Dataset <- read_csv("Dataset.csv")
#---- select the important variables ----#
new_df <- select(df, DistanceFromHome, MonthlyIncome, YearsAtCompany,
Attrition, BusinessTravel, OverTime, JobInvolvement,
StockOptionLevel, EnvironmentSatisfaction, JobLevel,
Department)
#---- Transform the Variables ----#
new_df <- new_df %>%
mutate(Attrition = ifelse(Attrition == "No", 0, 1),
OverTime = ifelse(OverTime == "No", 0, 1))
BusinessTravel ???