dist2 | 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
|
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
).
The definition of Canberra distance was wrong for negative data prior to version 1.3-5.
Friedrich Leisch
dist
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,])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.