title: Keep only two rows corresponding to an ID in a data frame
body: <p>I have the following data (this is a mock version) and I am using R.</p>
  
  <pre><code>ID m
  1  m1
  1  m2
  1  m3
  2  m1
  2  m2
  3  m1
  3  m2
  3  m3
  3  m4
  4  m1
  </code></pre>
  
  <p>Each ID has an m1 row and the rest of the m's are of variable length amongst the ID's. I would like to keep the m1 value and the last value corresponding to each ID. The ideal output would look like this:</p>
  
  <pre><code>ID m
  1  m1
  1  m3
  2  m1
  2  m2
  3  m1
  3  m4
  4  m1
  </code></pre>
  
  <p>Thank you very much in advance. </p>