View source: R/nearestTarget.R
nearestTarget | R Documentation |
Calculates the distances between a set of points and target locations. It identifies the nearest target for each point and checks if the distance is within a specified radius. If a target is found within the radius, its index and distance are returned; otherwise, -1 is returned for both.
nearestTarget(points, targets, r)
points |
A matrix or data frame containing the coordinates of the points with rows representing points. |
targets |
A matrix or data frame containing the coordinates of the target locations with rows representing targets. |
r |
A numeric value specifying the radius within which to consider targets. |
A data frame with two columns:
nt |
Index of the nearest target for each point. If no target is found within the radius, this will be -1. |
d |
Distance to the nearest target. If no target is found within the radius, this will be -1. |
# Define a set of points and targets
points <- matrix(c(1, 2, 3, 4), ncol = 2)
targets <- matrix(c(2, 3, 5, 6), ncol = 2)
radius <- 2
# Find the nearest targets
nearest_results <- nearestTarget(points, targets, radius)
# Print the results
print(nearest_results)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.