Skip to contents

Given the locations of different objects, this function determines the identity of the nearest neighboring object to each object.

Usage

nn(x, y, id, geo = FALSE)

Arguments

x

A vector of x (or longitude) coordinates.

y

A vector of y (or latitude) coordinates.

id

A vector corresponding to the unique identities of each track.

geo

A logical value indicating whether the locations are defined by geographic coordinates (pairs of longitude/latitude values). Default: FALSE.

Value

A vector of the same length as x and y representing the identity of the nearest neighboring object to each object.

See also

Author

Simon Garnier, garnier@njit.edu

Examples

x <- rnorm(25)
y <- rnorm(25, sd = 3)
id <- 1:25
nn(x, y, id)
#>  [1] 21  4 22 21  9 15 17 14  8  2  7 25 18  8 25 23 21 13 24  6  4  3 19 19 15