Computes a multivariate distance (one of: "manhattan", "euclidean", "chi", and "hellinger") between two vectors of the same length. It is used internally by
autoSum. This function has no buit-in error trapping procedures in order to speed up execution.
distance(x, y, method = "manhattan")
numeric vector of the same length as
character string naming a distance metric. Valid entries are: "manhattan", "euclidean", "chi", and "hellinger". Invalid entries will throw an error.
A number representing the distance between both vectors.
y are not checked to speed-up execution time. Distances are computed as:
d <- sum(abs(x - y))
d <- sqrt(sum((x - y)^2))
xy <- x + y
y. <- y / sum(y)
x. <- x / sum(x)
d <- sqrt(sum(((x. - y.)^2) / (xy / sum(xy))))
d <- sqrt(1/2 * sum(sqrt(x) - sqrt(y))^2)
Note that zeroes are replaced by 0.00001 whem
method equals "chi" or "hellinger".
#>  32.83516