Reputation: 25
I have two matrices which are built as follows
x1=cbind(V1,V2,ID)
X2=cbind(V1,V2,ID)
X3=rbind(X1,X2)
ID takes only the values "red" and "blue"
when I plot X1 and X2 I have the following plot
I want to select the data points which are within 1 unit distance (euclidian distance) basically filtering only the red points which are overlapping or quasi-overlapping a blue point or vice versa.
Red overlapping red and blue overlapping blue is not interesting for me.
Thanks a lot for your assistance.
Upvotes: 1
Views: 255
Reputation: 1854
You definitely need to provide a reproducible example for this one to get the best answer; however, I think below script will serve the purpose:
library(spatstat)
# setting seeds
set.seed(222)
# two different point patterns
X <- runifpoint(15)
Y <- runifpoint(20)
plot(X, pch=19, main="")
plot(Y, col="red", pch=19, add=T)
#you can get both which and dist from nncross
#N.which <- nncross(X,Y, k=1:20, what="which")
#N.dist <- nncross(X,Y, k=1:20, what="dist")
out <- subset(X, nncross(X,Y, k=1:20, what="dist") < 0.1) # you may change 0.1
plot(out, col="blue", pch=19, add=T)
For the above plot, black points represent X
and red points represent Y
. Blue are intersecting points which are within 0.1 unit distance. This distance can be further modified. For more detaild please see spatstat
to compute distances between two different datasets using nncross
.
Upvotes: 1