1

I was wondering if someone knows if there's an easy and smart way to revert a matrix (that was generated by calling "model.matrix" on a data frame) back into a data.frame? The reason being that I am using the matrix in a function where the original data frame is not in the scope and I want to try something with the data frame without modifying the whole code (before I know if what I'm trying is even useful ).

Thanks in advance!

  • There's a loss of information that occurs during model.matrix so it's not really invertible in the general case. See some info here: https://stackoverflow.com/questions/13435038/convert-a-model-matrix-in-r-to-a-group-vector. There may be special cases where it's possible. It would be easier to help if you provided some sort of [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that shows exactly what you are after. – MrFlick Jan 18 '22 at 08:12

0 Answers0