I have 3 polygons, which are: 1st is unique, 2 & 3 are equal. (I use SpatialPolygons
matrix but's not important). I just need to know how to implement a function to delete those duplicated polygons using following matrix:
d = rgeos::gEquals(sps, byid = T, returnDense = T)
1 2 3
1 FALSE FALSE FALSE
2 FALSE TRUE TRUE
3 FALSE TRUE TRUE
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.
I try something like this:
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
}
}
where in saved
I just need indices to leave (1,2) or (1,3) then I know what to do next.
EDIT
In fact, this post How can I remove all duplicates so that NONE are left in a data frame? is helpful, because applying
nd = !duplicated(d)
saved = as.numeric(rownames(d)[which(nd)])
I get the required result, but not sure it's correct when I have larger matrix.