| dist2 {flexclust} | R Documentation |
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.
dist2(x, y, method = "euclidean", p=2)
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. |
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).
Friedrich Leisch
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,])