43
I advise employing the caret package's dummyVars function:
Customers (id=c(10, 20, 30, 40, 50), gender=c("male," "female," "male," "female," mood=c("happy," "sad," "happy," "sad," "happy," outcome=c(1, 1, 0, 0, 0))
customers' gender, mood, and result
1-10 joyful males 1 2 20 females who are dejected 1 3 30 females who are joyful 0 4 40 males who are dejected 0 5 50 females who are joyful 0
# obscurate the data
Data = customers, dmy - dummyVars(" ."
data.frame(predict(dmy, newdata = customers), trsf)
gender of trsf.
gender is feminine.
male emotion
good mood
tragic result
1 10 0 1 1 0 1 2 20 1 0 0 1 3 30 1 0 1 0 0 4 40 0 1 0 1 0 5 50 1 0 1 0 0 Example source
You conduct both using the same process.
Transform data into actionable insights with our Data Analyst Certification – Enroll today!