Convert a matrix to vector and back

 You must use byrow = FALSE (the default) to convert the vector back to a matrix.

> (d <- matrix(1:6, nrow=2, ncol=3))
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
> (v <- as.vector(d))
[1] 1 2 3 4 5 6
> matrix(v, nrow=2, ncol=3, byrow = FALSE)
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

Commentaires

Posts les plus consultés de ce blog

Standard error from Hessian Matrix... what can be done when problem occurs

stepAIC from package MASS with AICc

Install treemix in ubuntu 20.04