title: Wide to long binary matrix adding counts
body: <p>I want to go from wide to long format but keeping the count value and factorizing the columns. I have this:</p>
  <pre><code>variable   LF1   LF2   LF3   LF4   LF5   Counts
  A           1     0     0     0     0      5 
  A           1     0     1     0     0      1    
  B           1     0     0     1     0      3 
  B           1     0     0     0     1      2 
  B           1     0     0     0     0      1 
  C           1     0     0     0     0      8 
  D           1     1     0     0     0      6 
  D           1     0     1     0     0      4
  </code></pre>
  <p>And I want the following:</p>
  <pre><code> variable   factor    count
      A         F1        6
      A         F3        1
      B         F1        6
      B         F4        3
      B         F5        2
      C         F1        8
      D         F1        10
      D         F2        6
      D         F3        4
  </code></pre>
  <p>This implies that data is simultaneously transformed to long while summing up the counts.
  I have tried with all combinations I can think of in reshape2 but I ran out of ideas e.g.</p>
  <pre><code>data_grouped &lt;- reshape2::melt(data, id.vars=c(&quot;variable&quot;))
  data_grouped &lt;- reshape2::melt(data, id.vars=c(&quot;variable&quot;,&quot;LF1&quot;,&quot;LF2&quot;,&quot;LF3&quot;,&quot;LF4&quot;,&quot;LF5&quot;))
  </code></pre>
  <p>Also I see that I can get something similar by concatenating the following:</p>
  <pre><code>data %&gt;% group_by(variable, LF1) %&gt;% summarise(sum(counts))
  data %&gt;% group_by(variable, LF2) %&gt;% summarise(sum(counts))
  </code></pre>
  <p>But this is very inefficient and not the ideal solution, therefore I'd really appreciate a hand on this.</p>