I have a data frame which has unique id's and categorical variables. I need to collapse all unique ids into a single row and all applicable categorical variables into distinct vectors so that I end with a matrix to be used for some regression analysis. ex:
id cat
1 a
2 b
1 b
3 c
4 a
2 a
4 c
3 c
output:
id cat.a cat.b cat.c
1 1 1 0
2 1 1 0
3 0 0 2
4 1 0 1
I've looked into the build.x function in the useful package but can't get past the issue of collapsing into a single id