title: How to group by in base R
body: <p>I would like to express the following SQL query using <strong>base R</strong> (without any particular package):</p>
  
  <pre><code>select month, day, count(*) as count, avg(dep_delay) as avg_delay
  from flights
  group by month, day
  having count &gt; 1000
  </code></pre>
  
  <p>It selects the mean departure delay and the number of flights per day on busy days (days with more than 1000 flights). The dataset is <a href="https://cran.r-project.org/web/packages/nycflights13/index.html" rel="noreferrer">nycflights13</a> containing information of flights departed from NYC in 2013.</p>
  
  <p>Notice I can easily write this in dplyr as:</p>
  
  <pre><code>flights %&gt;%
    group_by(month, day) %&gt;%
    summarise(count = n(), avg_delay = mean(dep_delay, na.rm = TRUE)) %&gt;%
    filter(count &gt; 1000)
  </code></pre>