r - Closest pair for any of a huge number of points -


we given huge set of points in 2d plane. need find, each point closest point within set. instance suppose initial set follows:

 foo <- data.frame(x=c(1,2,4,4,10),y=c(1,2,4,4,10)) 

the output should this:

 closespair(foo)  2  1  4  3  3 # (could 4 also) 

any idea?

the traditional approach preprocess data , put in data structure, k-d tree, "nearest point" query fast.

there implementation in nnclust package.

library(nnclust) foo <- cbind(x=c(1,2,4,4,10),y=c(1,2,4,4,10)) <- nnfind(foo)$neighbour plot(foo) arrows( foo[,1], foo[,2], foo[i,1], foo[i,2] ) 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -