Re: [R] how to re-shape a matrix

2013-04-03 Thread Sarah Goslee
Thanks for the reproducible example. Because this mixes numeric and character data, it's better done as a data frame than a matrix. > data.frame(rowind=as.vector(row(m)), colind=as.vector(col(m)), value = > as.vector(m)) rowind colind value 1 1 1 a 2 2 1 b 3

[R] how to re-shape a matrix

2013-04-03 Thread Hui Du
Hi All, I have a matrix like m <- matrix( letters[1:10], ncol=5) How to conver it to 10 * 3 matrix, which the first col is row index of m, second col is colum index of m and third column is the value of matrix, say 11 1"a" 21 2 "c" 1 3 "e" etc... Thanks.