Description Usage Arguments Details Value Author(s) Examples
Computes a multivariate distance (one of: "manhattan", "euclidean", "chi", and "hellinger") between two vectors of the same length. It is used internally by distanceMatrix
and autoSum
. This function has no buit-in error trapping procedures in order to speed up execution.
1 | distance(x, y, method = "manhattan")
|
x |
numeric vector. |
y |
numeric vector of the same length as |
method |
character string naming a distance metric. Valid entries are: "manhattan", "euclidean", "chi", and "hellinger". Invalid entries will throw an error. |
Vectors x
and y
are not checked to speed-up execution time. Distances are computed as:
manhattan
: d <- sum(abs(x - y))
euclidean
: d <- sqrt(sum((x - y)^2))
chi
:
xy <- x + y
y. <- y / sum(y)
x. <- x / sum(x)
d <- sqrt(sum(((x. - y.)^2) / (xy / sum(xy))))
hellinger
: d <- sqrt(1/2 * sum(sqrt(x) - sqrt(y))^2)
Note that zeroes are replaced by 0.00001 whem method
equals "chi" or "hellinger".
A number representing the distance between both vectors.
Blas Benito <blasbenito@gmail.com>
1 2 3 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.