# kNNdist

From dbscan v1.1-1
by Michael Hahsler

##### Calculate and plot the k-Nearest Neighbor Distance

Fast caclulation of the k-nearest neighbor distances in a matrix of points.
The plot can be used to help find a suitable value for the
`eps`

neighborhood for DBSCAN. Look for the knee in the plot.

##### Usage

```
kNNdist(x, k, ...)
kNNdistplot(x, k = 4, ...)
```

##### Arguments

- x
the data set as a matrix or a dist object.

- k
number of nearest neighbors used (use minPoints).

- ...
further arguments are passed on to

`kNN`

.

##### Details

See `kNN`

for a discusion of the kd-tree related parameters.

##### Value

`kNNdist`

returns a numeric vector with the distance to its k nearest
neighbor.

##### See Also

`kNN`

.

##### Examples

```
# NOT RUN {
data(iris)
iris <- as.matrix(iris[,1:4])
kNNdist(iris, k=4, search="kd")
kNNdistplot(iris, k=4)
## the knee is around a distance of .5
cl <- dbscan(iris, eps = .5, minPts = 4)
pairs(iris, col = cl$cluster+1L)
## Note: black are noise points
# }
```

*Documentation reproduced from package dbscan, version 1.1-1, License: GPL (>= 2)*

### Community examples

Looks like there are no examples yet.