Learn R Programming

BioTrajectory (version 1.1.0)

nearestTarget: Finds the nearest targets to a set of points within a specified radius.

Description

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.

Usage

nearestTarget(data, targets, r)

Value

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.

Arguments

data

An object of class `trajectory` containing a collection of points with coordinates.

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.