Created
February 20, 2012 03:39
-
-
Save rukku/1867642 to your computer and use it in GitHub Desktop.
Second nearest neighbor with crossdist using apply()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get pairwise distances from rp and ponderosa datasets | |
xpairs <- crossdist(rp, ponderosa) | |
#A function to get the second nearest neighbor | |
nncross2 <- function (x) sort(x)[2] | |
#Initialize the vector container for x.2 | |
x.2 <- numeric() | |
#Applies the nncross2 function to the xpairs matrix. | |
x.2 <- apply(xpairs, 1, nncross2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment