title: need Help to reshape data on R
body: <p>I'm looking for a way to reshape this kind of dataset :</p>
  
  <pre><code>mydata&lt;-data.frame(var=rep(c("A","B","C"),each=3),code=rep(c("x","y","z"),3),yearA=1:9,yearB=10:18,yearC=20:28)
  </code></pre>
  
  <p>ex:</p>
  
  <pre><code>var code    yearA   yearB   yearC
  A    x      1       10      20
  A    y      2       11      21
  A    z      3       12      22
  B    x      4       13      23
  B    y      5       14      24
  B    z      6       15      25
  C    x      7       16      26
  C    y      8       17      27
  C    z      9       18      28
  </code></pre>
  
  <p>to this :</p>
  
  <pre><code>code    year    var.A    var.B    var.C
  x       yearA    1       4        7
  x       yearB    10      13       16
  x       yearC    20      23       26
  y       yearA    4       5        8
  y       yearB    13      14       17
  y       yearC    23      24       27
  z       yearA    3       6        9
  z       yearB    12      15       18
  z       yearC    22      25       28
  </code></pre>
  
  <p>I try with melt, and reshape.. but the result is not what I would like. 
  Any idea ?</p>
  
  <p>thks</p>