Manhattan: Manhattan Numeric Comparator

View source: R/Manhattan.R

ManhattanR Documentation

Manhattan Numeric Comparator

Description

The Manhattan distance (a.k.a. L-1 distance) between two vectors x and y is the sum of the absolute differences of their Cartesian coordinates:

Manhattan(x,y) = sum_i { |x_i - y_i| }.

Usage

Manhattan()

Value

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

Note

The Manhattan distance is a special case of the Minkowski distance with p = 1.

See Also

Other numeric comparators include Euclidean, Minkowski and Chebyshev.

Examples

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

## Distance between rows (elementwise) of two matrices
comparator <- Manhattan()
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.