Description Usage Arguments Value See Also Examples
Calculate Minkowski distance between one point and a set of other points.
1 |
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. |
A numeric vector. These are distance^p, for speed of computation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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 = ""))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.