Given the locations of different objects, this function determines the distance of the nearest neighboring object to each object.
Arguments
- x
A vector of x (or longitude) coordinates.
- y
A vector of y (or latitude) coordinates.
- 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 distance to the nearest neighboring object for each object.
Author
Simon Garnier, garnier@njit.edu
Examples
x <- rnorm(25)
y <- rnorm(25, sd = 3)
id <- 1:25
nnd(x, y)
#> 1 2 3 4 5 6 7 8
#> 1.2076390 0.6071440 0.3208842 0.7446473 0.5268938 0.6071440 0.3208842 0.8663278
#> 9 10 11 12 13 14 15 16
#> 1.2076390 1.5719917 1.5719917 0.4417309 0.7373362 1.1673389 0.8942101 0.3615706
#> 17 18 19 20 21 22 23 24
#> 1.0906929 0.7766914 1.1461802 0.4160779 0.4417309 1.1461802 0.4160779 0.3615706
#> 25
#> 0.7373362