On 16/07/2016 6:25 PM, Ashta wrote: > Hi all, > > I have a large square matrix (60 x 60) and found it hard to > visualize. Is it possible to change it as shown below? > > Sample example (3 x 3) > > A B C > A 3 4 5 > B 4 7 8 > C 5 8 9 > > Desired output > A A 3 > A B 4 > A C 5 > B B 7 > B C 8 > C C 9
Yes, use matrix indexing. I don't think the 3600 values are going to be very easy to read, but here's how to produce them:
m <- matrix(1:3600, 60, 60) indices <- expand.grid(row = 1:60, col = 1:60) cbind(indices$row, indices$col, m[as.matrix(indices)]) Duncan Murdoch ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.