dist2 {flexclust}R Documentation

Compute Pairwise Distances Between Two Data sets

Description

This function computes and returns the distance matrix computed by using the specified distance measure to compute the pairwise distances between the rows of two data matrices.

Usage

dist2(x, y, method = "euclidean", p=2)

Arguments

x

A data matrix.

y

A vector or second data matrix.

method

the distance measure to be used. This must be one of "euclidean", "maximum", "manhattan", "canberra", "binary" or "minkowski". Any unambiguous substring can be given.

p

The power of the Minkowski distance.

Details

This is a two-data-set equivalent of the standard function dist. It returns a matrix of all pairwise distances between rows in x and y. The current implementation is efficient only if y has not too many rows (the code is vectorized in x but not in y).

Note

The definition of Canberra distance was wrong for negative data prior to version 1.3-5.

Author(s)

Friedrich Leisch

See Also

dist

Examples

x <- matrix(rnorm(20), ncol=4)
rownames(x) = paste("X", 1:nrow(x), sep=".")
y <- matrix(rnorm(12), ncol=4)
rownames(y) = paste("Y", 1:nrow(y), sep=".")

dist2(x, y)
dist2(x, y, "man")

data(milk)
dist2(milk[1:5,], milk[4:6,])

[Package flexclust version 1.4-2 Index]