Learn R Programming

omnibus (version 1.2.12)

pairDist: Calculate pairwise distances between two matrices or data frames.

Description

This function takes two data frames or matrices and returns a matrix of pairwise Euclidean distances between the two.

Usage

pairDist(x1, x2 = NULL, na.rm = FALSE)

Value

Matrix with nrow(x1) rows and nrow(x2) columns. Values are the distance between each row of x1 and row of x2.

Arguments

x1

Data frame or matrix one or more columns wide.

x2

Data frame or matrix one or more columns wide. If NULL, then pairwise distances between all points in x1 are calculated.

na.rm

Logical, if TRUE then any rows in x1 or x2 with at least one NA are removed first.

See Also

Examples

Run this code

x1 <- data.frame(x=sample(1:30, 30), y=sort(round(100 * rnorm(30))), z=sample(1:30, 30))
x2 <- data.frame(x=1:20, y=round(100 * rnorm(20)), z=sample(1:20, 20))
pairDist(x1, x2)
pairDist(x1)

Run the code above in your browser using DataLab