Learn R Programming

dbscan (version 1.1-9)

NN: NN --- Nearest Neighbors Superclass

Description

NN is an abstract S3 superclass for the classes of the objects returned by kNN(), frNN() and sNN(). Methods for sorting, plotting and getting an adjacency list are defined.

Usage

adjacencylist(x, ...)

# S3 method for NN adjacencylist(x, ...)

# S3 method for NN sort(x, decreasing = FALSE, ...)

# S3 method for NN plot(x, data, main = NULL, ...)

Arguments

x

a NN object

...

further parameters

decreasing

sort in decreasing order?

data

that was used to create x

main

title

Subclasses

kNN, frNN and sNN

See Also

Other NN functions: frNN(), kNNdist(), kNN(), sNN()

Examples

Run this code
# NOT RUN {
data(iris)
x <- iris[, -5]

# finding kNN directly in data (using a kd-tree)
nn <- kNN(x, k=5)
nn

# plot the kNN where NN are shown as line conecting points.
plot(nn, x)

# show the first few elements of the adjacency list
head(adjacencylist(nn))

# }
# NOT RUN {
# create a graph and find connected components (if igraph is installed)
library("igraph")
g <- graph_from_adj_list(adjacencylist(nn))
comp <- components(g)
plot(x, col = comp$membership)

# detect clusters (communities) with the label propagation algorithm
cl <- membership(cluster_label_prop(g))
plot(x, col = cl)
# }

Run the code above in your browser using DataLab