I was playing around a bit to see how I could find the two points in a set of points (or ordered pairs) furthest from each other.

Here's what I did:
1) created a Nrow by 2col matrix, so each row contains an x,y coordinate pair.

2) fed the matrix to a nested mapply (cv is my matrix):

mapply(function(k,l) mapply(function(x,y,a,b)
+ sqrt((x-a)^2+(y-b)^2),cv[,1],cv[,2],k,l),cv[,1],cv[,2])->alldist

Then I just did which.max(alldist) and found the original two points by figuring out what row, col the results of which.max referred to.

So, what's a better, or cleaner way to do all this? That is, is there a function in some package that will do anything like my nested mapply thing, and is there a better tool than which.max for locating a position in a matrix?

thanks
Carl

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to