I have this matrix and i want to get a 2 column matrix, where one column has the rowname and the other column, the colname of cells with value 1
x X1 X2 X3
You can do something like this :
mat <- which(x==1, arr.ind=TRUE) mat[,"col"] <- names(x)[mat[,"col"]] mat[,"row"] <- rownames(mat)
Which will give :
row col X1 "X1" "X1" X4 "X4" "X1" X2 "X2" "X2" X3 "X3" "X2" X1 "X1" "X3" X3 "X3" "X3"