Skip to contents

This function calculates the bearing angle and distance from each focal individual of a group to its nearest neighbor over time, across the sets of a dataset.

Usage

pairwise_metrics(
  data_list,
  geo = FALSE,
  verbose = FALSE,
  parallelize = FALSE,
  add_coords = FALSE
)

Arguments

data_list

A list of dataframes with groups timeseries per set. Columns must include: id, t, set, head, x, y.

geo

Logical, whether positions are geographic coordinates, default = FALSE.

verbose

Logical, whether to post updates on progress, default = FALSE.

parallelize

Logical, whether to run the function in parallel over timesteps, default = FALSE.

add_coords

Logical, whether data on relative positions are converted into geographic coordinates, default = 'FALSE'.

Value

A dataframe format of the input list, with new columns for nearest neighbor id (nn_id), bearing angles (bangl), and distances (nnd). If add_coords is TRUE, the columns nnx and nny are also added.

Author

Marina Papadopoulou m.papadopoulou.rug@gmail.com

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)
 )

pm <- pairwise_metrics(list(data), geo = FALSE)