If I have a factor variable, say x = factor(c(1, 2, 3)), then I can use the function model.matrixto create a dummy matrix:
model.matrix(~x + 0)
and I will get a matrix like:
x1 x2 x3
1 1 0 0
2 0 1 0
3 0 0 1
My question is, if I already have a large dummy matrix, how can I melt it to a column (factor)?
In another world, is there an inverse function of model.matrix?
Bayes source
share