i have a dataset for predicting the values that store will open in a certain area or not. I am confused to create dummy variables and want to know how to create dummies for variables Id,sales0,sales1,sales2,sales3,sales4,country,cosub,and many...if possible recommend me how to do that.....
Asked
Active
Viewed 33 times
1 Answers
1
You can use the {dummy} package
> library(dummy)
> df <- data.frame(name = c("A", "B", "B", "C", "D", "E", "E", "E"))
> dummy(df)
name_A name_B name_C name_D name_E
1 1 0 0 0 0
2 0 1 0 0 0
3 0 1 0 0 0
4 0 0 1 0 0
5 0 0 0 1 0
6 0 0 0 0 1
7 0 0 0 0 1
8 0 0 0 0 1
> cbind(df, dummy(df))
name name_A name_B name_C name_D name_E
1 A 1 0 0 0 0
2 B 0 1 0 0 0
3 B 0 1 0 0 0
4 C 0 0 1 0 0
5 D 0 0 0 1 0
6 E 0 0 0 0 1
7 E 0 0 0 0 1
8 E 0 0 0 0 1

abichat
- 2,317
- 2
- 21
- 39