title: reshape R data frame long to wide
body: <p>I'm trying to reshape my data from long to wide</p>
  <pre><code>set.seed(1)
  y &lt;- rnorm(12, 0, 1)
  x &lt;- rep(c(&quot;A&quot;,&quot;B&quot;), each=6)
  g &lt;- rep(c(&quot;g1&quot;, &quot;g2&quot;), each=3)
  t &lt;-  rep(c(1,2,3), times=4)
  df &lt;- data.frame(y=y, x=x, g=g, t=t)
  </code></pre>
  <p>This is what I'm hoping to get:</p>
  <pre><code>    A.1     A.2     A.3    B.1     B.2     B.3
  g1  -0.626  0.183  -0.835  0.487   0.738   0.575
  g2  1.595   0.329  -0.820  -0.305  1.511   0.389
  </code></pre>
  <p>I tried with <code>reshape</code></p>
  <pre><code>reshape(df, idvar = &quot;g&quot;, timevar = &quot;t&quot;, direction = &quot;wide&quot;)
  </code></pre>
  <p>but I don't know how to add <code>x</code> to the columns</p>