title: Create a column with a count of occurrences in R
body: <p>I am trying to add a column to an existing dataframe, such that the column defines the number of <em>different</em> products, each user has bought. A toy example is</p>
  
  <pre><code>Customer    Product
  1           Chocolate
  1           Candy
  1           Soda
  2           Chocolate
  2           Chocolate
  2           Chocolate
  3           Insulin
  3           Candy
  </code></pre>
  
  <p>Where the output should be</p>
  
  <pre><code>Customer    Product     #Products
  1           Chocolate   3
  1           Candy       3
  1           Soda        3
  2           Chocolate   1
  2           Chocolate   1
  2           Chocolate   1
  3           Insulin     2
  3           Candy       2
  </code></pre>
  
  <p>I would like to do this without a for loop, since I have millions of rows, and it would take forever. I have used data.table and other methods in order to just get the number of products for each customer, but I don't know how to easily add this as a column to the existing dataframe.</p>
  
  <p>Thanks in advance!</p>