I want to create a matrix of 0s and 1s based on the following data.
id <-c(1,1,1,2,2,3)
x<- c(5,7,8,2,6,5)
data_toy <- data.frame(id,x)
data_toy%>% count(id)
> data_toy%>% count(id)
id n
1 1 3
2 2 2
3 3 1
So based on the data, I need to create a 6X3 matrix where first column should be (1,1,1,0,0,0) and second column should be (0,0,0,1,1,0) so on.
Can you suggest anything to do this?
Thank you