frNN {dbscan}  R Documentation 
This function uses a kdtree to find the fixed radius nearest neighbors (including distances) fast.
frNN(
x,
eps,
query = NULL,
sort = TRUE,
search = "kdtree",
bucketSize = 10,
splitRule = "suggest",
approx = 0
)
## S3 method for class 'frNN'
sort(x, decreasing = FALSE, ...)
## S3 method for class 'frNN'
adjacencylist(x, ...)
## S3 method for class 'frNN'
print(x, ...)
x 
a data matrix, a dist object or a frNN object. 
eps 
neighbors radius. 
query 
a data matrix with the points to query. If query is not
specified, the NN for all the points in 
sort 
sort the neighbors by distance? This is expensive and can be
done later using 
search 
nearest neighbor search strategy (one of 
bucketSize 
max size of the kdtree leafs. 
splitRule 
rule to split the kdtree. One of 
approx 
use approximate nearest neighbors. All NN up to a distance of
a factor of 
decreasing 
sort in decreasing order? 
... 
further arguments 
If x
is specified as a data matrix, then Euclidean distances an fast
nearest neighbor lookup using a kdtree are used.
To create a frNN object from scratch, you need to supply at least the
elements id
with a list of integer vectors with the nearest neighbor
ids for each point and eps
(see below).
Selfmatches: Selfmatches are not returned!
frNN()
returns an object of class frNN (subclass of
NN) containing a list with the following components:
id 
a list of integer vectors. Each vector contains the ids of the fixed radius nearest neighbors. 
dist 
a list with distances (same structure as

eps 
neighborhood radius 
adjacencylist()
returns a list with one entry per data point in x
. Each entry
contains the id of the nearest neighbors.
Michael Hahsler
David M. Mount and Sunil Arya (2010). ANN: A Library for Approximate Nearest Neighbor Searching, http://www.cs.umd.edu/~mount/ANN/.
Other NN functions:
NN
,
comps()
,
kNNdist()
,
kNN()
,
sNN()
data(iris)
x < iris[, 5]
# Example 1: Find fixed radius nearest neighbors for each point
nn < frNN(x, eps = .5)
# Number of neighbors
hist(sapply(adjacencylist(nn), length),
xlab = "k", main="Number of Neighbors",
sub = paste("Neighborhood size eps =", nn$eps))
# Explore neighbors of point i = 10
i < 10
nn$id[[i]]
nn$dist[[i]]
plot(x, col = ifelse(1:nrow(iris) %in% nn$id[[i]], "red", "black"))
# get an adjacency list
head(adjacencylist(nn))
# plot the fixed radius neighbors (and then reduced to a radius of .3)
plot(nn, x)
plot(frNN(nn, eps = .3), x)
## Example 2: find fixedradius NN for query points
q < x[c(1,100),]
nn < frNN(x, eps = .5, query = q)
plot(nn, x, col = "grey")
points(q, pch = 3, lwd = 2)