title: How to most efficiently melt a data.frame with multiple measured column groups
body: <p>I have a data frame of the form:</p>
  <pre><code>df &lt;- data.frame(&quot;id_1&quot; = seq(1,100, 1),
                   &quot;id_2&quot; = seq(1,100, 1),
                   &quot;id_3&quot; = seq(1,100, 1),
                   &quot;m1_g1&quot; = seq(1,100, 1),
                   &quot;m2_g1&quot; = seq(2,200, 2),
                   &quot;m3_g2&quot; = seq(3,300, 3),
                   &quot;m4_g2&quot; = seq(4,400, 4))
  
  </code></pre>
  <p>I would like to melt this so that the id columns serve as id's, but then I effectively have 2 rows per original entry that show me the m1-m4 columns where m1-m2 are of the same measure type (g1) and m3-m4 are of another measure type (g2)</p>
  <p>The final data frame would look like this:</p>
  <pre><code>   id_1    id_2    id_3   var   value_1    value_2
  1    1       1       1     1       1           3
  2    1       1       1     2       2           4
  3    2       2       2     1       2           6
  4    2       2       2     2       4           8
  </code></pre>
  <p>I've tried using melt to create separate melted data frames and then pasting over the column, but I feel there has got to be a better way.</p>
  <p>Thank you all!</p>
  <pre><code></code></pre>