title: R equivalent of .first or .last sas operator
body: <p>Does anybody know what is the best R alternative to SAS first. or last. operators? I did find none.</p>
  
  <p>SAS has the FIRST. and LAST. automatic variables, which identify the first and last record amongst a group with the same value with a particular variable; so in the following dataset FIRST.model and LAST.model are defined:</p>
  
  <pre><code>Model,SaleID,First.Model,Last.Model
  Explorer,1,1,0
  Explorer,2,0,0
  Explorer,3,0,0
  Explorer,4,0,1
  Civic,5,1,0
  Civic,6,0,0
  Civic,7,0,1
  </code></pre>