I would like to convert my dataframe into a matrix that expands a single factor column into multiple ones and assigns a 1
/0
depending on the factor. For example
C1 C2 C3
A 3 5
B 3 4
A 1 1
Should turn into something like
C1_A C1_B C2 C3
1 0 3 5
0 1 3 4
1 0 1 1
How can I do this in R? I tried data.matrix
, as.matrix
which did not return what I wanted. They assign an "integer" value to a single factor column, there is no expansion.