I'm trying to turn every variable in my database into dummy variables:
>dados
X1 X2 X3
1 1 3 1
2 3 2 1
3 3 2 1
4 2 3 2
5 2 3 3
I'm trying to create binary vectors for this. But, I can not do it right. Since I have 3 categories per variable, the number of dummy variables is: k-1 dummy variables . This would result in 2 artificial variables per variable.
What I tried was this:
library(mlr)
createDummyFeatures(dados,cols=NULL)
1 2 3
1 1 0 0
2 0 0 1
3 0 0 1
4 0 1 0
5 0 1 0
6 0 0 1
7 0 1 0
8 0 1 0
9 0 0 1
10 0 0 1
11 1 0 0
12 1 0 0
13 1 0 0
14 0 1 0
15 0 0 1
Why does this return me 3 variables per variable (since k-1 dummy variables should be two). Also, they are in the same column! How do I solve these problems? They should look like this:
a b c d e f
1 1 0 0 0 1 0
2 0 0 0 1 1 0
3 0 0 0 1 1 0
4 0 1 0 0 0 1
5 0 1 0 0 0 0