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
Here's one line answer
x ## X1 X2 X3 ## X1 1 0 1 ## X2 0 1 0 ## X3 0 1 1 ## X4 1 0 0 cbind(rownames(x)[row(x) * x], colnames(x)[col(x) * x]) ## [,1] [,2] ## [1,] "X1" "X1" ## [2,] "X4" "X1" ## [3,] "X2" "X2" ## [4,] "X3" "X2" ## [5,] "X1" "X3" ## [6,] "X3" "X3"