title: How to collapse a matrix in R while getting min and max of some columns
body: <p>I have the following data frame in R. It represents a made up protein structure for ease of explanation. </p>
  
  <pre><code>Uniprots Chain resSeq Serial
  P68871  D   23  3446
  P68871  D   24  3453
  P68871  D   25  3457
  P68871  D   26  3461
  P68871  D   27  3470
  P69011  A   38  3561
  P69011  A   39  3568
  P69011  A   40  3577
  P69011  A   41  3588
  P69011  A   42  3599
  P69011  A   43  3610
  P69011  A   44  3619
  P69011  A   45  3625
  P69011  A   46  3636
  P0116   B   2   4239
  P0116   B   4   4242
  P0116   B   5   4268
  P0116   B   6   4279
  P0116   B   7   4285
  P0116   B   8   4299
  P0116   B   9   5015
  P0116   C   15  5055
  P0116   C   30  5199
  P0116   C   42  5239
  </code></pre>
  
  <p>What I want is to collapse it down so it looks like this:</p>
  
  <pre><code>Uniprot Chain resSeq_start resSeq_end Serial_start Serial_end
  P68871   D      23            27          3446       3470
  P69011   A      38            46          3561       3636
  P0116    B       2             9          4239       5015
  P0116    C      15            42          5055       5239
  </code></pre>
  
  <p>Basically, I want to collapse down over the first 1,2 and 3 columns. I can then use the the 4th column as a check that it worked. I thought I could do this with aggregate but that doesn't seem to work. I can definitely do this with some messy for loops (keep appending to a vector till a new uniprot/chain) but that's ugly.</p>
  
  <p>One thing to note is that Uniprot/Chain combinations are not always unique. Specifically, a uniprot can have multiple chains (as in my example). </p>
  
  <p>Thank you for your help!</p>