Compute the nearest neighbour index map of an object, and return it as a function.
1 2 3 4 5 6 7
Any suitable dataset representing a two-dimensional
collection of objects,
such as a point pattern (object of class
A single integer. The
Extra arguments are ignored.
String (partially matched) specifying whether to return the
index of the neighbour (
For a collection X of two dimensional objects
(such as a point pattern or a line segment pattern),
the “nearest neighbour index function”
of X is the mathematical function f such that, for any
two-dimensional spatial location (x,y),
the function value
is the index i identifying the closest member of X.
That is, if i = f(x,y) then X[i] is the closest member of
the collection X to the location (x,y).
f <- nnfun(X) returns a function
in the R language, with arguments
x,y, that represents the
nearest neighbour index function of
X. Evaluating the function
in the form
v <- f(x,y), where
are any numeric vectors of equal length containing coordinates of
spatial locations, yields the indices of the nearest neighbours
to these locations.
If the argument
k is specified then the
neighbour will be found.
The result of
f <- nnfun(X) also belongs to the class
"funxy" and to the special class
It can be printed and plotted immediately as shown in the Examples.
nnfun object can be converted to a pixel image
function with arguments
The function also belongs to the class
"nnfun" which has
a method for
"funxy" which has methods
1 2 3 4 5 6 7 8 9 10 11 12 13
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.