Learn R Programming

fields (version 1.7.2)

rdist: Euclidean distance matrix

Description

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

Usage

rdist(x1, x2)

Arguments

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