nearest: Nearest sites

Description Usage Arguments Examples

Description

Return a vector or martrix(in row) of the nearest sites to a target.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
nearest(x, ...)

## Default S3 method:
nearest(h, n)

## S3 method for class 'matrix'
nearest(h, n, rm.target = FALSE)

## S3 method for class 'numeric'
nearest(ii, n, h, rm.target = FALSE)

Arguments

h

Matrix of distance or a distance object

n

Numbers of neighbors

ii

Index of the target site

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
xcoord <- replicate(2,runif(50))
xdis <- as.matrix(dist(xcoord))

nearest(1,10,xdis)
nearest(xdis,10)

## if you wanted the indices only
t(apply(nearest(xdis,10),2,which))

## if the target is included in the distance, but not wanted
nearest(1,10,xdis, rm.target = TRUE)
nearest(xdis[1:5,1:5],3, rm.target = TRUE)

## idem ii = 0 implies that the target is zero distance
nearest(0, 20, xdis[2,])
nearest(2, 20, xdis)

martindurocher/floodRFA documentation built on June 5, 2019, 8:44 p.m.