title: R is it possible to get the output of table() using dcast?
body: <p>I have the following data frame:</p>
  
  <pre><code>id&lt;-c(1,2,3,4,1,1,2,3,4,4,2,2)
  period&lt;-c("first","calib","valid","valid","calib","first","valid","valid","calib","first","calib","valid")
  df&lt;-data.frame(id,period)
  </code></pre>
  
  <p>typing</p>
  
  <pre><code>table(df) 
  </code></pre>
  
  <p>results in</p>
  
  <pre><code>period
  id  calib first valid
  1     1     2     0
  2     2     0     2
  3     0     0     2
  4     1     1     1
  </code></pre>
  
  <p>Is there any way to get the same result using 'dcast' and save it as a new data frame?</p>