title: Select the first and last row by group in a data frame
body: <p>How can I select the first and last row for each unique <code>id</code> in the following dataframe?</p>
  <pre><code>tmp &lt;- structure(list(id = c(15L, 15L, 15L, 15L, 21L, 21L, 22L, 22L, 
  22L, 23L, 23L, 23L, 24L, 24L, 24L, 24L), d = c(1L, 1L, 1L, 1L, 
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), gr = c(2L, 1L, 
  1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L), mm = c(3.4, 
  4.9, 4.4, 5.5, 4, 3.8, 4, 4.9, 4.6, 2.7, 4, 3, 3, 2, 4, 2), area = c(1L, 
  2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 3L)), .Names = c(&quot;id&quot;, 
  &quot;d&quot;, &quot;gr&quot;, &quot;mm&quot;, &quot;area&quot;), class = &quot;data.frame&quot;, row.names = c(NA, 
  -16L))
  tmp
  #&gt;    id d gr  mm area
  #&gt; 1  15 1  2 3.4    1
  #&gt; 2  15 1  1 4.9    2
  #&gt; 3  15 1  1 4.4    1
  #&gt; 4  15 1  1 5.5    2
  #&gt; 5  21 1  1 4.0    2
  #&gt; 6  21 1  2 3.8    2
  #&gt; 7  22 1  1 4.0    2
  #&gt; 8  22 1  1 4.9    2
  #&gt; 9  22 1  2 4.6    2
  #&gt; 10 23 1  1 2.7    2
  #&gt; 11 23 1  1 4.0    2
  #&gt; 12 23 1  2 3.0    2
  #&gt; 13 24 1  1 3.0    2
  #&gt; 14 24 1  1 2.0    3
  #&gt; 15 24 1  1 4.0    2
  #&gt; 16 24 1  2 2.0    3
  </code></pre>