data(iris)
# Find fixed radius nearest neighbors for each point
nn <- frNN(iris[,-5], eps=.5)
# Number of neighbors
hist(sapply(nn$id, 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(iris[,-5], col = ifelse(1:nrow(iris) %in% nn$id[[i]], "red", "black"))
## manually create a frNN object for dbscan (dbscan only needs ids and eps)
nn <- list(ids = list(c(2,3), c(1,3), c(1,2), c(3,5), c(4,5)), eps = 1)
class(nn) <- "frNN"
nn
dbscan(nn, minPts = 2)
Run the code above in your browser using DataLab