We start by changing the name of the BostonHousing data to simply data for ease of use. Independent variables that are of the factor type are then converted to the numeric type using the lapply function.
Take a look at the following code:
# Converting factor variables to numeric
data <- BostonHousing
data %>% lapply(function(x) as.numeric(as.character(x)))
data <- data.frame(data)
In the preceding code, after converting factor variables to the numeric type, we also change the format of data to data.frame.