Skip to contents

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: id, t, head, x, y. The calculations are based on the swaRm package.

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 (nnx, nny). This can be useful for visualization purposes but it is not used in the package pipeling. Default = 'FALSE'.

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

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

nnm <- nn_metrics(data, geo = FALSE)