title: dplyr min on specific values
body: <p>I'd like to do the equivalent of the following <code>SQL</code> query in R with <code>dplyr</code>:</p>
  
  <pre><code>SELECT 
    user_id,
    min(case when product = 'ProductA' then purchase_date end) AS min_purchase_date_product_A,
    min(case when product = 'ProductB' then purchase_date end) AS min_purchase_date_product_B
  FROM fact_purchase
  GROUP BY user_id;
  </code></pre>
  
  <p>I think I would need to use the <code>min()</code> function in combination with <code>which()</code> (see proposal below) but the syntax is wrong and I don't know how to combine these two functions!</p>
  
  <pre><code>min_purchase_dates_per_product =
  fact_purchase %&gt;%
  group_by(user_id) %&gt;%
  mutate(
  min_purchase_date_product_A = min(which(product == 'ProductA')),
  min_purchase_date_product_B = min(which(product == 'ProductB'))
  )
  </code></pre>
  
  <p>If there is a way to do it for all existing products instead of listing one by one the products in a mutate statement, I'm happy to know how to do it.</p>