title: Selecting unique rows in matrix using R
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13279582/select-only-the-first-rows-for-each-unique-value-of-a-column-in-r">Select only the first rows for each unique value of a column in R</a>  </p>
  </blockquote>
  
  
  
  <p>I have a matrix of the following form:</p>
  
  <pre><code>col1 col2
  
  1    2   
  1    2    
  1    2   
  1    2   
  1    2
  2    5
  2    5
  2    5
  3    7
  3    7
  3    7
  3    7
  3    7
  3    7
  3    7
  3    7
  4    2 
  4    2 
  4    2
  </code></pre>
  
  <p>I would like to select all the unique rows based on 'col1'.</p>
  
  <p>which in this case would be the first row from each unique value in col1:</p>
  
  <p>subset:</p>
  
  <pre><code>col1   col2
  1      2 
  2      5
  3      7
  4      2
  </code></pre>
  
  <p>Here's what I've tried:</p>
  
  <pre><code>https://dl.dropbox.com/u/22681355/matrix.csv
  mat&lt;-read.csv("matrix.csv")
  sub&lt;-unique(mat$V1)
  subset(mat, mat==c(sub)
  </code></pre>
  
  <p>It spits out much more than I would expect to get and I get this error mesage:</p>
  
  <p>Warning message:
  In contacts$V1 == c(g) :
    longer object length is not a multiple of shorter object length</p>