Learn R Programming

patterncausality (version 0.1.3)

metricDistance: Calculate Generalized Minkowski Distance Between Two Vectors

Description

This function calculates the generalized Minkowski distance of order 'n' between two numeric vectors. This distance is a metric in a normed vector space which generalizes the Euclidean and Manhattan distances. It is used for various data science applications, particularly in clustering, optimization, and outlier detection in complex systems.

Usage

metricDistance(vec1, vec2, n)

Value

Numeric, the computed Minkowski distance between the two vectors.

Arguments

vec1

Numeric vector, the first vector for which the distance will be calculated.

vec2

Numeric vector, the second vector for which the distance will be calculated.

n

Integer, the order of the Minkowski distance. When n=2, it becomes the Euclidean distance; when n=1, it becomes the Manhattan distance.

Examples

Run this code
vec1 <- c(1, 2, 3)
vec2 <- c(4, 5, 6)
n <- 2
distance <- metricDistance(vec1, vec2, n)
print(distance)

Run the code above in your browser using DataLab