I have a raw dataset like this:
ID Click
1 A
1 B
1 E
2 A
2 Q
3 B
3 D
3 F
And what I am planning to do is to transpose it into a sparse matrix like this:
ID A B D E Q F
1 1 1 0 1 0 0
2 1 0 0 0 1 0
3 0 1 1 0 0 1
The column number of a sparse matrix is numbers of unique 'click' value in raw data. The row number of sparse matrix is the numbers of unique 'ID' numbers in raw data. If the "click" appears in a specific ID in raw dataset, then the value will be 1, otherwise the value is 0.
I tried reshape()
function in R but it's not work. Can anyone help with it? Thanks!