Skip to content

Instantly share code, notes, and snippets.

@rukku
Created February 8, 2012 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rukku/1767479 to your computer and use it in GitHub Desktop.
Save rukku/1767479 to your computer and use it in GitHub Desktop.
Gets the second nearest neighbor using spatstat's crossdist
#get pairwise distances from rp and ponderosa datasets
xpairs <- crossdist(rp, ponderosa)
#Initialize vector container for X.2
X.2 = numeric()
#Sort rows and get second nearest neighbor
for (i in 1:nrow(xpairs) {
x <- sort(xpairs[i,])[2]
X.2 <- append(X.2, x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment