Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

distance

Calculate the squared Euclidean distance between pairs of points


Description

Calculate the squared Euclidean distance between pairs of points and return a distance matrix

Usage

distance(X1, X2 = NULL)

Arguments

X1

a matrix or data.frame containing real-valued numbers

X2

an optional matrix or data.frame containing real-valued numbers; must have ncol(X2) = ncol(X1)

Details

If X2 = NULL distances between X1 and itself are calculated, resulting in an nrow(X1)-by-nrow(X1) distance matrix. Otherwise the result is nrow(X1)-by-nrow(X2) and contains distances between X1 and X2.

Calling distance(X) is the same as distance(X,X)

Value

The output is a matrix, whose dimensions are described in the Details section above

Author(s)

Robert B. Gramacy rbg@vt.edu

See Also

Examples

x <- seq(-2, 2, length=11)
X <- as.matrix(expand.grid(x, x))
## predictive grid with NN=400
xx <- seq(-1.9, 1.9, length=20)
XX <- as.matrix(expand.grid(xx, xx))

D <- distance(X)
DD <- distance(X, XX)

laGP

Local Approximate Gaussian Process Regression

v1.5-5
LGPL
Authors
Robert B. Gramacy <rbg@vt.edu>, Furong Sun <furongs@vt.edu>
Initial release
2019-08-27

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.