Convert a matrix to a 1 dimensional array

后端 未结 10 1499
忘了有多久
忘了有多久 2020-11-27 14:45

I have a matrix (32X48).

How can I convert the matrix into a single dimensional array?

10条回答
  •  迷失自我
    2020-11-27 15:08

    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
    

提交回复
热议问题