1

I have a matrix with 1 and 0 in it. Now I want to create a csv-file with the following syntax where only the values=1 were printed:

j1.i1, 1

j1.i2, 1

j2.i2, 1 ...

j1 should be the name of the row 1

i1 should be the name of column 1 and so on...

Edit:

M1 = matrix(c(1, 0, 1, 0, 1, 0), nrow=2, ncol=3, byrow = TRUE)
row.names(M1) <- c(100, 101)
colnames(M1) <- c("A", "B", "C")
M1

    A B C
100 1 0 1
101 0 1 0

If we take this easy example the solution i'm looking for is:

100.A, 1
100.C, 1
101.B, 1
päde
  • 9
  • 3
  • 2
    `which(mat == 1, arr.ind = TRUE)` could be helpful here where `mat` is the name of your matrix. – Ronak Shah Mar 29 '17 at 09:10
  • 3
    Please give a reproducable example if you want a detailed answer. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jogo Mar 29 '17 at 09:16

0 Answers0