# [R] R version 3.3.2, Windows 10: How to identify the common coordinates in two different SpatialPixelDataFrame

Rathore, Saubhagya Singh saubhagya at gatech.edu
Mon Mar 27 16:07:30 CEST 2017

```Hello Everyone,

I am resending this message as due to some reason, the message was not posted on the list before.

I have two SpatialPixelDataFrames (a and b) which have few common coordinates/locations. I need to identify these common coordinates and remove them from both the dataframes.

Though I have been able to identify and separate common coordinate points (an2 and bn2), but I feel my code is very inefficient. Is there is better way to do it. I have shared my code here.

Secondly, I am also not sure about how can I remove these locations from the original dataframes "a" and "b".

Thank You
#-----code starts---------------------

# separating the points with same coordinates

a<-data.frame(x=c(1,4,6,3,2),y=c(1,3,5,2,9),z=c(5,6,7,8,3))
b<-data.frame(x=c(2,4,2,3,4),y=c(9,3,6,7,4),z=c(3,6,3,4,9))
gridded(a) = ~x+y
gridded(b) = ~x+y

# comparing x coordinates
res <- outer(a at coords[,1], b at coords[,1], `==`)

# an and bn have common x coordinates
index.temp<-which(res,arr.ind = T)
an<-a[unique(index.temp[,1]),]
bn<-b[unique(index.temp[,2]),]

#comparing y coordinates
res <- outer(an at coords[,2], bn at coords[,2], `==`)
index.temp<-which(res,arr.ind = T)

#an2 and bn2 have comon x and y coordinates
an2<-an[unique(index.temp[,1]),]
bn2<-bn[unique(index.temp[,2]),]

#--code ends-----------------------------------

Thank You
Saubhagya

[[alternative HTML version deleted]]

```