Learn R Programming

fields (version 1.2)

rdist: Euclidean distance matrix

Description

Given two sets of locations computes the Euclidean distance matrix among all pairings.

Usage

rdist(x1, x2)

Arguments

x1
Matrix of first set of locations where each row gives the coordinates of a particular point.
x2
Matrix of second set of locations where each row gives the coordinates of a particular point. If this is missing x1 is used.

Value

  • The distance matrix if nrow(x1)=m and nrow( x2)=n then the returned matrix will be mXn.

Details

Let D be the mXn distance matrix. The elements are the Euclidean distances between the all locations x1[i,] and x2[j,].

D.ij = sqrt( sum.k (( x1[i,k] - x2[j,k]) **2 ).

FORTRAN: The default function calls FORTRAN to evaluate the distances. A pure S code version also exists: rdist.S

See Also

exp.cov, rdist.earth

Examples

Run this code
out<- rdist( ozone$x)
# out is a 20X20 matrix.
out2<- rdist( ozone$x[1:5,], ozone$x[11:20,])
#out2 is a 5X10 matrix

Run the code above in your browser using DataLab