How to one hot encode several categorical variables in R

I recommend using the dummyVars function in the caret package: customers <- data.frame( id=c(10, 20, 30, 40, 50), gender=c(‘male’, ‘female’, ‘female’, ‘male’, ‘female’), mood=c(‘happy’, ‘sad’, ‘happy’, ‘sad’,’happy’), outcome=c(1, 1, 0, 0, 0)) customers id gender mood outcome 1 10 male happy 1 2 20 female sad 1 3 30 female happy 0 4 40 male … Read more