[R] how to vectorize a matrix

Christian Ritz ritz at kvl.dk
Mon May 22 11:17:32 CEST 2006


Hi Lorenzo,

maybe the following example is of use?


a <- matrix(1:25,5,5)

stack(as.data.frame(a[, c(1,3,5,2,4)])) 


Note that 'stack' takes a data frame or list as first argument (not a
matrix). Therefore the matrix is first converted to a data frame using
'as.data.frame'.

Christian



More information about the R-help mailing list