The matrix that I have:
> dput(head(data1))
structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 1, 0, 0), .Dim = c(6L, 18L), .Dimnames = list(c("AT1G01050",
"AT1G01080", "AT1G01090", "AT1G01320", "AT1G01470", "AT1G01800"
), c("10", "33.95", "58.66", "84.42", "110.21", "134.16", "164.69",
"199.1", "234.35", "257.19", "361.84", "432.74", "506.34", "581.46",
"651.71", "732.59", "817.56", "896.24")))
To simplify the explanation, I will show the following table:
10 33.95 58.66 84.42 110.21 134.16 164.69 199.1 234.35 257.19 361.84 432.74 506.34 581.46 651.71 732.59 817.56 896.24
AT1G01050 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0
AT1G01080 0 0 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1
AT1G01090 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0
AT1G01320 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1
AT1G01470 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
AT1G01800 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0
As you can see, my table is full 0and 1. In many cases, there is more than one in each row 1. So, what I would like to do is duplicate / copy lines to leave one 1in each line. So, for an example, take the first line:
10 33.95 58.66 84.42 110.21 134.16 164.69 199.1 234.35 257.19 361.84 432.74 506.34 581.46 651.71 732.59 817.56 896.24
AT1G01050 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0
There are two numbers on this line 1. This means that I have to create another line for this "gene". So the result should look like this. I leave first 1(starting from the left) in the data, but delete the second. To distinguish later, we must also change the name of the string:
10 33.95 58.66 84.42 110.21 134.16 164.69 199.1 234.35 257.19 361.84 432.74 506.34 581.46 651.71 732.59 817.56 896.24
AT1G01050_1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
1 .
10 33.95 58.66 84.42 110.21 134.16 164.69 199.1 234.35 257.19 361.84 432.74 506.34 581.46 651.71 732.59 817.56 896.24
AT1G01050_2 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
, , , - , .