Learn R Programming

VBmix (version 0.3.2)

gdist:

Description

dist computes distances between pairs of elements: 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

gdist(g1, g2, metric = NULL, norm=FALSE)

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.
norm
If TRUE, a ln det term is added to distances in order to mitigate the prevalence of metrics reflecting large variance.

Value

n1 x n2 matrix of distances

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.

See Also

dist, mkmeans

Examples

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

Run the code above in your browser using DataLab