xysort(x, y, order=F)
A greedy algorithm is used, finding the nearest neighbor to the first point, then the nearest neighbor to that point, etc. The algorithm has complexity O(length(x)^2).
Jon Louis Bentley (1982). Writing Efficient Programs. Prentice-Hall, Englewood Cliffs, NJ.
plot( xysort(x,y) )xyo <- xysort(x, y, order=T) plot(xyo, type="n") text(xyo, label[xyo$order])