Last chance! 50% off unlimited learning
Sale ends in
## S3 method for class 'ppx':
nndist(X, \dots, k=1)
"ppx"
).coords.ppx
to determine
which coordinates should be used.k
th nearest neighbour. If k = 1
(the default), the return value is a
numeric vector v
such that v[i]
is the
nearest neighbour distance for the i
th data point.
If k
is a single integer, then the return value is a
numeric vector v
such that v[i]
is the
k
th nearest neighbour distance for the
i
th data point.
If k
is a vector, then the return value is a
matrix m
such that m[i,j]
is the
k[j]
th nearest neighbour distance for the
i
th data point.
NA
value is returned if the
distance is not defined (e.g. if there is only one point
in the point pattern).k
is specified, it computes the
distance to the k
th nearest neighbour. The function nndist
is generic; this function
nndist.ppx
is the method for the class "ppx"
.
The argument k
may be a single integer, or an integer vector.
If it is a vector, then the $k$th nearest neighbour distances are
computed for each value of $k$ specified in the vector.
If there is only one point (if x
has length 1),
then a nearest neighbour distance of Inf
is returned.
If there are no points (if x
has length zero)
a numeric vector of length zero is returned.
To identify which point is the nearest neighbour of a given point,
use nnwhich
.
To find the nearest neighbour distances from one point pattern
to another point pattern, use nncross
.
By default, both spatial and temporal coordinates are extracted.
To obtain the spatial distance between points in a space-time point
pattern, set temporal=FALSE
.
nndist
,
pairdist
,
nnwhich
df <- data.frame(x=runif(5),y=runif(5),z=runif(5),w=runif(5))
X <- ppx(data=df)
# nearest neighbours
d <- nndist(X)
# second nearest neighbours
d2 <- nndist(X, k=2)
# first, second and third nearest
d1to3 <- nndist(X, k=1:3)
Run the code above in your browser using DataLab