I have the following matrix ‘x’
a b
a 1 3
b 2 4
It is a really large matrix (trimmed down for this question)
I would like to print out this matrix by each row name and column name combination along with the value in that cell. So the expected output would be
a,a,1
a,b,3
b,a,2
b,b,4
I could loop through them, but I’m pretty sure this can be avoided (apply?). Any pointers much appreciated.
One way is to use the
meltfunction from thereshape2package.Edit
If your data is so big that speed is an issue, I would also suggest:
Edit2
After testing with relatively big data, I would not rule out
melt: