title: How to remove duplicates using equality matrix in R?
body: <p>I have 3 polygons, which are: 1st is unique, 2 &amp; 3 are equal. (I use <code>SpatialPolygons</code> matrix but's not important). I just need to know how to implement a function to delete those duplicated polygons using following matrix:</p>
  
  <pre><code>d = rgeos::gEquals(sps, byid = T, returnDense = T)
  
        1     2     3
  1 FALSE FALSE FALSE
  2 FALSE  TRUE  TRUE
  3 FALSE  TRUE  TRUE
  </code></pre>
  
  <p>So I need to leave 1 and remove 2 or 3. I have only this short data but if I have longer and will do mistake here it would not work further although it may work for short example. Anyway, this doesn't work at all, because I don't know how to make it stick.</p>
  
  <p>I try something like this:</p>
  
  <pre><code>saved = NULL
        for (i in 1:nrow(d)) {  #i=1
          e = which(d[i,] == T)
          if (any(e == T)) {
            # saved
            saved = c(saved, i)
            d[i,] = F; d[,i] = F
          }
        }
  </code></pre>
  
  <p>where in <code>saved</code> I just need indices to leave (1,2) or (1,3) then I know what to do next. </p>
  
  <p>EDIT</p>
  
  <p>In fact, this post <a href="https://stackoverflow.com/q/13763216/680068">How can I remove all duplicates so that NONE are left in a data frame?</a> is helpful, because applying</p>
  
  <pre><code>nd = !duplicated(d)
  saved = as.numeric(rownames(d)[which(nd)])
  </code></pre>
  
  <p>I get the required result, but not sure it's correct when I have larger matrix. </p>