I wish to convert part of my data to binary wide format.
This is my input:
mydf <- data.frame( transaction =c (1,0,1,1,1,0,0), quality = c("NEW", "OLD","OLD", "OLD","OLD","NEW","NEW"), brand = c(1,2,3,1,2,2,1))
transaction quality brand
1 1 NEW 1
2 0 OLD 2
3 1 OLD 3
4 1 OLD 1
5 1 OLD 2
6 0 NEW 2
7 0 NEW 1
>
and I wish to convert the brand
column to wide format so that have the following output
transaction quality brand_1 brand_2 brand_3
1 1 NEW 1 0 0
2 0 OLD 0 1 0
3 1 OLD 0 0 1
4 1 OLD 1 0 0
5 1 OLD 0 1 0
6 0 NEW 0 1 0
7 0 NEW 1 0 0
I tried different approaches such as model.matrix
function but couldn't reach to my desired output.