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@coords[,1], b@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@coords[,2], bn@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]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to