Alos Alos - 2 months ago 7
R Question

How to convert a matrix to a 1 dimensional array in R?

I have a large matrix (32X48).
How can I convert the matrix into a single dimensional array in R?

Answer

If we're talking about data.frame, then you should ask yourself are the variables of the same type? If that's the case, you can use rapply, or unlist, since data.frames are lists, deep down in their souls...

 data(mtcars)
 unlist(mtcars)
 rapply(mtcars, c) # completely stupid and pointless, and slower
Comments