nn_metrics {swaRmverse} | R Documentation |
Nearest Neighbour Metrics
Description
This function calculates the bearing angle and distance from all focal individuals in a group to their nearest neighbor over time.
Usage
nn_metrics(
data,
add_coords = FALSE,
geo = FALSE,
verbose = FALSE,
parallelize = FALSE
)
Arguments
data |
A dataframe with the group's positional timeseries for one set.
Column names must include: |
add_coords |
Logical, whether the data on relative positions of
nearest neighbours should be converted into
coordinates in the reference frame of the focal individual ( |
geo |
Logical, whether positions are geographic coordinates, default = FALSE. |
verbose |
Logical, whether to post updates on progress. |
parallelize |
Logical, whether to parallelize the function over time. |
Value
The input dataframe with new columns for nearest neighbor id (nn_id
),
bearing angle (bangl
), and distance (nnd
).
If add_coords
is TRUE, the columns nnx
and nny
are added.
Author(s)
Marina Papadopoulou m.papadopoulou.rug@gmail.com
See Also
add_rel_pos_coords, group_metrics
Examples
data <- data.frame(
set = rep("1", 50),
t = as.POSIXct(rep(1:25, 2), origin = Sys.time()),
id = c(rep(1, 25), rep(2, 25)),
x = rnorm(50),
y = rnorm(50),
head = runif(50, 0, 2 * pi)
)
nnm <- nn_metrics(data, geo = FALSE)