Lets say I have a matrix mat which has both column names and row names:
mat <- matrix(1:25, ncol = 5)
rownames(mat) <- LETTERS[1:5]
colnames(mat) <- LETTERS[6:10]
^^ Simple and reproducible example to make the following matrix:
F G H I J
A 1 6 11 16 21
B 2 7 12 17 22
C 3 8 13 18 23
D 4 9 14 19 24
E 5 10 15 20 25
I need to turn this matrix into a data frame that looks like the following:
ROWNAME COLNAME VALUE
A F 1
B F 2
C F 3
......
Is there a function built in to do this? How would I tackle such a problem.
Also, this matrix would be one of many matrices so there would need to be a Matrix Name column added so that it could parse over multiple matrices and create a data.frame that is actually 4 columns and as many observations as values in all of the matrices combined. If there is a shortcut for any of these steps it would be greatly appreciated.