title: Sort two rows into one row in R
body: <p>I have large dataset like the following:</p>
  
  <pre><code>myd &lt;- data.frame (var1 = c("A", "A", "B1-1", "B1-1", "C", "C", "D1", "D1"),
                     var2 = c(1,    2,    2,       2,     3,  1,   1,    4))
   var1 var2
  1    A    1
  2    A    2
  3 B1-1    2
  4 B1-1    2
  5    C    3
  6    C    1
  7   D1    1
  8   D1    4
  </code></pre>
  
  <p>Please note that each level in var1 is repeated twice and has two values in var2.</p>
  
  <p>For each levels of var1, I want to create a new dataset where var2 values are now in row wise (shorted) and combined into one column with following type of output:</p>
  
  <pre><code>   var1    var2.h1 var2.h2      h1.h2  
  1    A      1         2           12
  2   B1-1    2         2           22
  3    C      1         3           13
  4   D1      1         4           14
  </code></pre>