title: extract last row for each subject from a data frame
body: <p>I have a data frame in R like this. I would like to extract the last visit for each subject.     </p>
  
  <p>SUBJID VISIT  </p>
  
  <pre><code>   40161       3  
     40161       4  
     40161       5  
     40161       6  
     40161       9  
     40201       3  
     40202       6  
     40202       8  
     40241       3  
     40241       4 
  </code></pre>
  
  <p>The desired output is as follows</p>
  
  <p>SUBJID VISIT    </p>
  
  <pre><code>   40161     9  
     40201     3  
     40202     8  
  </code></pre>
  
  <p>How should I do this in R? Thanks very much for your help.  </p>