Learn R Programming

patterncausality (version 0.1.3)

distanceVector: Calculate Distances Between a Reference Point and Multiple Candidates

Description

This function applies the 'metricDistance' function to calculate distances from a given reference point to each row in a matrix of candidate nearest neighbors. It is particularly useful in the situation between matrix and a vector

Usage

distanceVector(point, candidateNNs, n)

Value

Numeric vector, distances from the reference point to each of the candidate points.

Arguments

point

Numeric vector, the reference point from which distances are calculated.

candidateNNs

Matrix, rows represent candidate points to which distance from the reference point is calculated.

n

Integer, the order of the Minkowski distance to use.

Examples

Run this code
point <- c(1, 2, 3)
candidateNNs <- matrix(c(4, 5, 6, 7, 8, 9), nrow = 2, byrow = TRUE)
n <- 2
distances <- distanceVector(point, candidateNNs, n)
print(distances)

Run the code above in your browser using DataLab