If I understand you correctly, you need to smooth the matrix.
You can use as.vector and rep to add id columns, for example.
m = cbind(c(1,2,3),c(4,5,6),c(7,8,9)) row.names(m) = c('R1','R2','R3') colnames(m) = c('C1','C2','C3') d <- data.frame(i=rep(row.names(m),ncol(m)), j=rep(colnames(m),each=nrow(m)), score=as.vector(m))
Result:
> m C1 C2 C3 R1 1 4 7 R2 2 5 8 R3 3 6 9 > d ij score 1 R1 C1 1 2 R2 C1 2 3 R3 C1 3 4 R1 C2 4 5 R2 C2 5 6 R3 C2 6 7 R1 C3 7 8 R2 C3 8 9 R3 C3 9
Note that this code converts the matrix to data.frame , since row and column names can be string, and you cannot have a matrix with a different column type.
If you are sure that all row and column names are numbers, you can force them on the matrix.
source share