data(iris)
x <- iris[, -5]
# Example 1: Find fixed radius nearest neighbors for each point
nn <- frNN(x, eps = .5)
nn
# Number of neighbors
hist(lengths(adjacencylist(nn)),
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 fixed-radius 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)
Run the code above in your browser using DataLab