Learn R Programming

condvis (version 0.5-1)

dist1: Minkowski distance

Description

Calculate Minkowski distance between one point and a set of other points.

Usage

dist1(x, X, p = 2, inf = FALSE)

Arguments

x

A numeric vector describing point coordinates.

X

A numeric matrix describing coordinates for several points.

p

The power in Minkowski distance, defaults to 2 for Euclidean distance.

inf

Logical; switch for calculating maximum norm distance (sometimes known as Chebychev distance) which is the limit of Minkowski distance as \(p\) tends to infinity.

Value

A numeric vector. These are distance^p, for speed of computation.

See Also

similarityweight

Examples

Run this code
# NOT RUN {
x <- runif(5000)
y <- runif(5000)

x1 <- 0.5
y1 <- 0.5

dev.new(width = 4, height = 5.3)
par(mfrow = c(2, 2))

for(p in c(0.5, 1, 2, 10)){
  d <- dist1(x = c(x1, y1), X = cbind(x, y), p = p) ^ (1/p)
  col <- rep("black", length(x))
  col[d < 0.3] <- "red"
  plot(x, y, pch = 16, col = col, asp = 1, main = paste("p = ", p, sep = ""))
}

# }

Run the code above in your browser using DataLab