distance_functions: Euclidean and Manhattan Distance

Description Usage Arguments Value Author(s) See Also Examples

Description

Returns the squared Euclidean distance or the Manhattan distance between all rows in x and the vector center.

Usage

1
2
euclidean(x, center, ...)
manhattan(x, center, ...)

Arguments

x

a matrix or data frame, or a vector to be interpreted as a one-row matrix.

center

a vector such that length(center) = ncol(x).

...

no effect; included for signature compatibility with mahalanobis.

Value

A vector of which the ith element is the squared Euclidean distance or the Manhattan distance between x[i,] and center.

Author(s)

Daniel Dvorkin

See Also

mahalanobis in package stats.

Examples

1
2
3
4
5
6
set.seed(123)
x <- matrix(rnorm(12), ncol=3)
euclidean(x, rep(0,3))
# [1] 0.8026151 3.1930442 4.1403916 1.7348174
manhattan(x, rep(0,3))
# [1] 1.376616 2.390904 3.243706 1.695383

lcmix documentation built on May 2, 2019, 6:49 p.m.