Euclidean: Euclidean Numeric Comparator

View source: R/Euclidean.R

EuclideanR Documentation

Euclidean Numeric Comparator

Description

The Euclidean distance (a.k.a. L-2 distance) between two vectors x and y is the square root of the sum of the squared differences of the Cartesian coordinates:

Euclidean(x, y) = sqrt(sum_i { (x_i - y_i)^2 })

Usage

Euclidean()

Value

A Euclidean instance is returned, which is an S4 class inheriting from Minkowski.

Note

The Euclidean distance is a special case of the Minkowski distance with p = 2.

See Also

Other numeric comparators include Manhattan, Minkowski and Chebyshev.

Examples

## Distance between two vectors
x <- c(0, 1, 0, 1, 0)
y <- seq_len(5)
Euclidean()(x, y)

## Distance between rows (elementwise) of two matrices
comparator <- Euclidean()
x <- matrix(rnorm(25), nrow = 5)
y <- matrix(rnorm(5), nrow = 1)
elementwise(comparator, x, y)

## Distance between rows (pairwise) of two matrices
pairwise(comparator, x, y)


comparator documentation built on March 18, 2022, 6:15 p.m.