Learn R Programming

SCORPIUS (version 1.0.4.1)

knn_distances: k Nearest Neighbour distances

Description

knn_distances returns the distances of the k nearest neighbours of each sample.

Usage

knn_distances(dist, k, self_loops = FALSE)

Arguments

dist

A numeric matrix, data frame or "dist" object.

k

The maximum number of nearest neighbours to search.

self_loops

TRUE if samples with the same index or name are allowed to be neighbours.

Value

A matrix containing the distances of the k nearest neighbours of each sample.

Examples

Run this code
# NOT RUN {
## Calculate the kNN distances within a set of samples
x <- matrix(rnorm(50*10, mean=0, sd=1), ncol=10)
dist <- dist(x)
knnd <- knn_distances(dist, 10)
plot(density(knnd))

## Calculate the kNN distances between two sets of samples
library(dynutils)
y <- matrix(rnorm(100*10, mean=1, sd=2), ncol=10)
dist <- calculate_distance(x, y, "euclidean")
knnd <- knn_distances(dist, 10)
plot(density(knnd))
# }

Run the code above in your browser using DataLab