I have a column vector in a dataframe and would like to turn it into a binary matrix so I can do matrix multiplication with it later on.
y_labels
1
4
4
3
desired output
1 0 0 0
0 0 0 1
0 0 0 1
0 0 1 0
In Octave I would do something like y_matrix = (y_labels == [1 2 3 4])
. However, I can't figure out how to get this in R. Anybody know how?