distance | R Documentation |
Computes Manhattan, Euclidean, Chi, or Hellinger distances between numeric vectors of the same length. Used internally within [distanceMatrix()] and [autoSum()].
distance(x, y, method = c("manhattan", "chi", "hellinger", "euclidean"))
x |
(required, numeric vector). |
y |
(required, numeric vector) of same length as 'x'. |
method |
(required, character string) name of a distance metric. Valid entries are: "manhattan", "euclidean", "chi", and "hellinger". |
Vectors x
and y
are not checked to speed-up execution time. Distances are computed as:
"manhattan": 'sum(abs(x - y))'
"euclidean": 'qrt(sum((x - y)^2))'.
"chi": 'xy <- x + y' 'y. <- y / sum(y)' 'x. <- x / sum(x)' 'sqrt(sum(((x. - y.)^2) / (xy / sum(xy))))'
"hellinger": 'sqrt(1/2 * sum((sqrt(x) - sqrt(y))^2))'
Note that zeroes are replaced by 'mean(c(x, y)) * 0.001' whem 'method' is "chi" or "hellinger".
A distance value.
Blas Benito <blasbenito@gmail.com>
distance(
x = runif(100),
y = runif(100),
method = "manhattan"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.