title: Cast to find frequency of pairs in "R"
body: <p>If I have the following data:</p>
  
  <pre><code>id &lt;- c(1,2,3,4,5,3,5,4)
  type &lt;- c(1,2,2,3,1,3,2,2)
  df &lt;- data.frame(id,type)
  
    id type
  1  1    1
  2  2    2
  3  3    2
  4  4    3
  5  5    1
  6  3    3
  7  5    2
  8  4    2
  </code></pre>
  
  <p>Suppose I want to get the frequency count of every (id,type) so that I get the following dataframe.</p>
  
  <pre><code>df.want &lt;- data.frame(id = c(1,2,3,4,5),x.1 = c(1,0,0,0,1),x.2 = c(0,1,1,1,1),x.3 = c(0,0,1,1,0))
  
  df.want
  
    id x.1 x.2 x.3
  1  1   1   0   0
  2  2   0   1   0
  3  3   0   1   1
  4  4   0   1   1
  5  5   1   1   0
  </code></pre>
  
  <p>So for each ID I want the frequency of each type as a row. I tried <code>cast(df,id ~ type,summary)</code>but get:</p>
  
  <pre><code>Using type as value column.  Use the value argument to cast to override this choice
  Error in `[.data.frame`(data, , variables, drop = FALSE) : 
    undefined columns selected
  </code></pre>
  
  <p>I think I might be close. Any ideas?</p>