Learn R Programming

SCORPIUS (version 1.0)

euclidean_distance: (Pairwise) Euclidean distances between two sets of samples

Description

euclidean_distance calculates the (pairwise) Euclidean distances between one or two sets of samples.

Usage

euclidean_distance(x, y)

Arguments

x

A numeric matrix or data frame with M rows (one per sample) and P columns (one per feature).

y

NULL (default) or a numeric matrix or data frame with N rows (one per sample) and P columns (one per feature).

Value

An M-by-M (if y is NULL) or an M-by-N (otherwise) matrix containing the Euclidean distances between the given sets of samples.

Examples

Run this code
# NOT RUN {
## generate two matrices with 50 and 100 samples
x <- matrix(rnorm(50*10, mean=0, sd=1), ncol=10)
y <- matrix(rnorm(100*10, mean=1, sd=2), ncol=10)
dist <- euclidean_distance(x, y)

## compare with the standard dist function
dist2 <- as.matrix(dist(rbind(x, y)))[1:50, 51:150]
plot(dist, dist2)
# }

Run the code above in your browser using DataLab