title: efficient way to double aggregation for a data frame
body: <p>I have a questions regarding to aggregation a data frame double times, and involves re-formate the table. </p>
  
  <p>I have a table, contains two columns: name, and category. The category is factor variable, contains 10 levels, say '0' to '9'. So the data frame looks like:</p>
  
  <pre><code>name   category
  a        0
  a        1
  a        1
  a        4
  a        9
  b        2
  b        2
  b        2
  b        3
  b        7
  b        8
  c        0
  c        0
  c        0
  </code></pre>
  
  <p>The result I want to aggregate looks like this:</p>
  
  <pre><code>name category.0  category.1  category.2 category.3 category.4 ..... category.9
  a        1           2            0         0           1               1
  b        0           0            3         1           0               0            
  c        3           0            0         0           0               0
  </code></pre>
  
  <p>it counts how many '0','1',...,'9' for each unique name.</p>
  
  <p>What I did to generate the result, is to use a simple aggregate function</p>
  
  <pre><code>new_df &lt;- aggregate(category ~ name,df, FUN=summary)
  </code></pre>
  
  <p>and then unlist the second columns of new_df to get the result.</p>
  
  <p>However, it is too slow. I would like to know if there is more efficient way to do this. </p>