title: Select first and last row from grouped data
body: <p><strong>Question</strong></p>
  <p>Using <code>dplyr</code>, how do I select the top and bottom observations/rows of grouped data in one statement?</p>
  <p><strong>Data &amp; Example</strong></p>
  <p>Given a data frame:</p>
  <pre><code>df &lt;- data.frame(id=c(1,1,1,2,2,2,3,3,3), 
                   stopId=c(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;a&quot;,&quot;b&quot;,&quot;c&quot;), 
                   stopSequence=c(1,2,3,3,1,4,3,1,2))
  </code></pre>
  <p>I can get the top and bottom observations from each group using <code>slice</code>, but using two separate statements:</p>
  <pre><code>firstStop &lt;- df %&gt;%
    group_by(id) %&gt;%
    arrange(stopSequence) %&gt;%
    slice(1) %&gt;%
    ungroup
  
  lastStop &lt;- df %&gt;%
    group_by(id) %&gt;%
    arrange(stopSequence) %&gt;%
    slice(n()) %&gt;%
    ungroup
  </code></pre>
  <p>Can I combine these two statements into one that selects <em>both</em> top and bottom observations?</p>