Pairwise distance between groups

Share:

Description

dist computes distances between every pair of elements in a group: gdist takes two arguments, and returns the matrix of distances wrt every possible pair with one argument from each group. General Mahalanobis metrics are also allowed.

Usage

1
gdist(g1, g2, metric = NULL)

Arguments

g1

n1 x d matrix with n1 data elements.

g2

n2 x d matrix with n2 data elements.

metric

If NULL, defaults to identity (i.e. Euclidean distance). A d x d matrix is assumed as a sample covariance matrix, and its inverse is used to compute distances (i.e. Mahalanobis distance). Likewise, a list of n2 d x d matrices can be provided, yielding distances specific to each row in g2.

Details

This function is especially useful to make algorithms such as k-means (or mkmeans in the package) more efficient - rows in g1 are then generally the data set, and in g2 respectively cluster centres.

Value

n1 x n2 matrix of distances

Author(s)

P. Bruneau

See Also

dist, mkmeans

Examples

1
dists <- gdist(irisdata, irisdata[c(1,11,21),])

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.