distance | R Documentation |
Distance
distance(
x,
y,
type = c("euclidean", "squared euclidean", "manhattan", "minkowski", "chebyshev",
"jaccard", "soergel", "geographical"),
...
)
x |
A numeric vector. |
y |
A numeric vector. |
type |
The type of the distance measure. |
... |
Optional arguments. |
The following types of distance measures are implemented:
Euclidean: \sqrt(\sum(x_i - y_i)^2)
Squared Euclidean: \sum(x_i - y_i)^2
Manhattan: \sum |x_i - y_i|
Minkowski: (\sum |x_i - y_i|^p)^(1/p)
Chebyshev: max |x_i - y_i|
Jaccard: 1 - Jaccard similarity
Soergel: 1 - Ruzicka similarity
Geographical distance based on longitude and latitude values expected for both x
and y
. Usually longitude and latitude values are given in degree, an automatically conversion to radian is made.
The distance between x
and y
.
Other Utils:
as_ANN_matrix()
,
degree()
,
list_as_numeric()
,
probability()
,
radian()
,
random_seed()
,
re.factor()
,
sd_pop()
,
similarity()
,
var_pop()
,
vector_as_ANN_matrix()
,
vector_as_numeric()
# Euclidean distance
x <- c(20, 1, 41, 13, 5, 69)
y <- c(11, 2, 23, 4, 10, 67)
distance(x, y)
# Geographical distance
geo_coord <- c("longitude", "latitude")
regensburg <- setNames(c(49.013432, 12.101624), geo_coord)
kiel <- setNames(c(54.323292, 10.122765), geo_coord)
distance(regensburg, kiel, type = "geographical")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.