View source: R/getMaxPairDist.R
getMaxPairDist | R Documentation |
Calculates the maximum of pairwise distances between points given a set of coordinates.
getMaxPairDist(xy) ## S3 method for class 'data.frame' getMaxPairDist(xy) ## Default S3 method: getMaxPairDist(xy)
xy |
either a numerical (n x p)-matrix with the coordinates of n points in p-dimensional space (1 row of coordinates per point), or a data frame with either the variables |
A list with the following components
d |
numerical value with the maximum pairwise distance between points. |
idx |
a vector with two entries giving the row indices of the points that are farthest apart. |
# coordinates given by a suitable data frame (maxPD <- getMaxPairDist(DFsavage)) # plot points and point pair with maximum distance plot(point.y ~ point.x, data=DFsavage, asp=1, pch=16) x0 <- DFsavage$point.x[maxPD$idx[1]] # 1st point x y0 <- DFsavage$point.y[maxPD$idx[1]] # 1st point y x1 <- DFsavage$point.x[maxPD$idx[2]] # 2nd point x y1 <- DFsavage$point.y[maxPD$idx[2]] # 2nd point y segments(x0, y0, x1, y1, col="green3", lwd=2) # coordinates given by a matrix ## Not run: xy <- matrix(round(rnorm(20, 100, 15), 1), ncol=2) getMaxPairDist(xy) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.