nearNeighb: Find nearest neighbours within a radius

View source: R/nearNeighb.R

nearNeighbR Documentation

Find nearest neighbours within a radius

Description

Find nearest neighbours within a radius

Usage

nearNeighb(x, y = NULL, k = NULL, radius = NULL, zones = NULL)

Arguments

x

two column matrix of individual x and y coordinates

y

optional two column matrix of individual x and y coordinates

k

number of neighbours to search for, starting from nearest in coordinate space. If NULL, radius must be provided.

radius

radius to look for nearest neighbours, in units of XY coordinates. If NULL, k must be provided.

zones

number of zones of equal arc angle, e.g. zones = 4 results in four zones each with 90deg arc. If NULL, no zones are defined. If zones are defined, the nearest competitor within each zone is returned. If zones are defined, radius must also be defined.

Details

If y is provided, nearest neighbours of individuals in y are identified for each individual in x, otherwise, nearest neighbours in x are identified.

In the case of ties, the first nearest neighbour is returned.

Value

List of dataframes per focal individual in x, of neighbours, their distances and angles relative to the focal individual. If no competitors are found within the radius of a focal individual, NA is returned for all columns except focal ID.

Examples

data(bicuar)

nearNeighb(bicuar[,c("x", "y")], k = 4)
nearNeighb(bicuar[1:10, c("x", "y")], bicuar[, c("x", "y")], radius = 5)
nearNeighb(bicuar[,c("x", "y")], radius = 5, zones = 4)


johngodlee/compInd documentation built on Aug. 5, 2024, 8:44 a.m.