Learn R Programming

neighbr (version 1.0.3)

distance: Calculate the distance between two vectors.

Description

Calculate the distance between two vectors.

Usage

distance(x, y, measure)

Arguments

x, y

Numeric vectors.

measure

Distance measure ("euclidean" or "squared_euclidean").

Value

The distance between x and y.

Details

Distance measures in this package are based on those defined in the PMML specification. Distances are calculated using the following equations:

Euclidean: \((\sum((x_i - y_i)^2))^0.5\) Squared euclidean: \(\sum((x_i - y_i)^2)\)

The input vectors must be of the same length.

See Also

similarity, PMML comparison measures

Examples

Run this code
# NOT RUN {
distance(c(-0.5,1),c(0.4,1.6),"euclidean")
distance(c(-0.5,1),c(0.4,1.6),"squared_euclidean")

# }

Run the code above in your browser using DataLab