computeDistIdx | R Documentation |
computeDistIdx
computes the indices of entries in a
distance matrix (as computed by dist
) that hold
the distances between a given point and one or more other points.
computeDistIdx(n, i,
j = setdiff(1:n,
i), includeMyself = FALSE)
n |
number of points |
i |
index of point to compute distance from |
j |
index of point(s) to compute distance to |
includeMyself |
if TRUE, and |
a vector of indices of entries in the distance matrix related to
the distances from the i
-th point to the other points.
The indices of entries corresponding to the distance between
point j
and point i
are sorted in increasing order
according to j
. If includeMyself
is TRUE
,
the returned vector includes an extra NA
element
corresponding to the non-existing index into the distance matrix
holding the distance between point i
and point i
itself. This makes the length of the returned vector to be equal
to n
, such that the index corresponding to the distance
between point i
and point j
resides at position
j
in the returned vector.
Tomas Sieger
computeIdxFromDistIdx
x <- 1:10
d <- dist(x)
# entries holding distances between the 3rd point and all the
# other points
computeDistIdx(length(x), 3)
# include an extra \code{NA} at the 3rd position to make the vector easily indexable
i <- computeDistIdx(length(x), 3, includeMyself = TRUE)
i
# the distance between point 3 and 4:
d[i[4]]
# entries holding distances between the 3rd point and points 5 and 7
computeDistIdx(length(x), 3, c(5, 7))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.