"nnwhich"(X, ..., k=1)
"ppx"
).
coords.ppx
to determine
which coordinates should be used.
k
th nearest neighbour.
k
th nearest neighbour).If k = 1
(the default), the return value is a
numeric vector v
giving the indices of the nearest neighbours
(the nearest neighbout of the i
th point is
the j
th point where j = v[i]
).If k
is a single integer, then the return value is a
numeric vector giving the indices of the
k
th nearest neighbours.If k
is a vector, then the return value is a
matrix m
such that m[i,j]
is the
index of the k[j]
th nearest neighbour for the
i
th data point.
NA
is returned if there is only one point
in the point pattern.k
is specified, the algorithm finds
each point's k
th nearest neighbour. The function nnwhich
is generic. This is the method
for the class "ppx"
.
If there are no points in the pattern,
a numeric vector of length zero is returned.
If there is only one point,
then the nearest neighbour is undefined, and a value of NA
is returned. In general if the number of points is less than or equal
to k
, then a vector of NA
's is returned.
To evaluate the distance between a point and its nearest
neighbour, use nndist
.
To find the nearest neighbours 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
.
nnwhich
,
nndist
,
nncross
df <- data.frame(x=runif(5),y=runif(5),z=runif(5),w=runif(5))
X <- ppx(data=df)
m <- nnwhich(X)
m2 <- nnwhich(X, k=2)
Run the code above in your browser using DataLab