title: Aggregate & count rows that match condition, group by unique values & transform table
body: <p>There must be a simple and elegant way of doing this in R with data.table package, but I have trouble figuring it out. Vectorized operations are preferable.</p>
  
  <pre><code>library(data.table)    
  d1 &lt;- as.Date("01-13-2013", '%m-%d-%Y')    
  d2 &lt;- as.Date("12-31-2013", '%m-%d-%Y')    
  data &lt;- data.frame(Date=sample(seq(d1,d2,1),10), Customer_ID=sample(1:5,20,replace=T), Product=sample(letters[1:5]), Store=sample(c("S1","S2")))
  </code></pre>
  
  <p>create</p>
  
  <pre><code>ID Date_Prod_A Times_Purchased_A Date_Prod_C Times_Purchased_C
  
  1 47  01-01-2012                 2           -                 -
  2 26           -                 -  01-17-2012                 1
  </code></pre>
  
  <p>Find the list of all values for product and add two columns per each product.
  Also, create a table that shows how many different products appear for each ID.</p>
  
  <hr>
  
  <pre><code>table &lt;- data.table(data)
  </code></pre>