title: Count n_distinct with a condition
body: <p>I have the following dataframe:</p>
  
  <pre><code>df&lt;-data.frame(Name= c(rep("A",3), rep("B",5)), Month = c(1,2,3,1,2,3,3,3), Volume = c(50,0,50,50,50,50,50,50))
  </code></pre>
  
  <p>and I would like to update a column "Count" to represent the number of unique Months per Name:</p>
  
  <pre><code>df&lt;-df%&gt;%
    group_by(Name) %&gt;%
    mutate(Count = n_distinct(Month))
  </code></pre>
  
  <p>However, how can I add a filter such that I only count Months whose corresponding Value > 0? This is my desired output:</p>
  
  <pre><code>df&lt;-data.frame(Name= c(rep("A",3), rep("B",5)), Month = c(1,2,3,1,2,3,3,3), Volume = c(50,0,50,50,50,50,50,50), Count = c(2,2,2,3,3,3,3,3))
  </code></pre>
  
  <p>Thank you!</p>