title: dplyr n_distinct with condition
body: <p>Using dplyr to summarise a dataset, I want to call n_distinct to count the number of unique occurrences in a column. However, I also want to do another summarise() for all unique occurrences in a column where a condition in another column is satisfied.</p>
  
  <p>Example dataframe named "a":</p>
  
  <pre><code>A B
  1 Y
  2 N
  3 Y
  1 Y
  </code></pre>
  
  <p><code>a %&gt;% summarise(count = n_distinct(A))</code></p>
  
  <p>However I also want to add a count of <code>n_distinct(A)</code> where <code>B == "Y"</code></p>
  
  <p>The result should be:</p>
  
  <pre><code>count
      3
  </code></pre>
  
  <p>when you add the condition the result should be:</p>
  
  <pre><code>count
      2
  </code></pre>
  
  <p>The end result I am trying to achieve is both statements merged into one call that gives me a result like</p>
  
  <pre><code>count_all  count_BisY
          3           2
  </code></pre>
  
  <p>What is the appropriate way to go about this with dplyr?</p>