This blog is a repository of cool things relating to statistical computing, simulation and stochastic modeling. (Inspired by Andrew Gelman's blog--the first useful blog I've seen.)
Friday, October 15, 2010
I foolishly tried to convert a matrix M to a vector using vector:
vector(M)
But this is done column wise, so that adjacent row items end up non-adjacent.
c(t(M)) works too. The advantage of unmatrix(), according to the docs, is that it gives the resulting vector appropriate names. (If you look at the code of unmatrix() you'll see that most of it is taken up with constructing names: the actual data manipulation is done via c(x) or c(t(x)) depending on whether byrow is FALSE or TRUE.
2 comments:
Or you could simply do as.vector(t(M))
I think you mean
library(gdata)
c(t(M)) works too.
The advantage of unmatrix(), according to the docs, is that it gives the resulting vector appropriate names. (If you look at the code of unmatrix() you'll see that most of it is taken up with constructing names: the actual data manipulation is done via c(x) or c(t(x)) depending on whether byrow is FALSE or TRUE.
Post a Comment