title: Using dcast to widen a data frame
body: <p>I have the following data frame:</p>
  
  <pre><code>z &lt;- data.frame(
                  item=letters[rep(24:26,2)],
                  freq=c(4,3,2,4,4,1),
                  id=rep(1:2,each=3)
                 )
  
  item freq id
  x    4    1
  y    3    1
  z    2    1
  x    4    2
  y    4    2
  z    1    2
  </code></pre>
  
  <p>The data frame is unique on every <code>id,item</code> combination.</p>
  
  <p>I would it to be like this:</p>
  
  <pre><code>id x y z
   1 4 3 2
   2 4 4 1
  </code></pre>
  
  <p>This looks like a fairly simple transform but I can't seem to get it to work.</p>
  
  <p>Here is what I have tried (<code>z</code> is the name of the data frame):</p>
  
  <pre><code>dcast(z,id ~ item,sum)
  </code></pre>
  
  <p>and it returns this:</p>
  
  <pre><code>id x y z
  1 1 1 1
  2 2 2 2
  </code></pre>
  
  <p>What am I doing wrong?</p>