title: Conditional count in data frame
body: <p>I have a dataframe (df) with three columns like so:</p>
  
  <p><strong>Structure:</strong></p>
  
  <pre><code>id id1 age
  A1 a1  32
  A1 a2  45
  A1 a3  45
  A1 a4  12
  A2 b1  15
  A2 b5  34
  A2 b64 17
  </code></pre>
  
  <p><strong>Expected Output:</strong></p>
  
  <pre><code>id count count1
  A1 4     1
  A2 3     2
  </code></pre>
  
  <p><strong>Logic:</strong></p>
  
  <ul>
  <li>Column "count" is the number of times "id" is repeated</li>
  <li>Column "count1" is the number of rows where age is less than 21</li>
  </ul>
  
  <p><strong>Current Code:</strong></p>
  
  <pre><code>library(dplyr)
  df_summarized &lt;- df %&gt;% 
                       group_by(id) &gt;%&gt; 
                       summarise(count = n(),count1 = count(age&lt;21)) 
  </code></pre>
  
  <p><strong>Problem:</strong></p>
  
  <pre><code>Error: no applicable method for 'group_by_' applied to an object of class "logical"
  </code></pre>