Learn R Programming

fields (version 5.02)

rdist: Euclidean distance matrix

Description

Given two sets of locations computes the full Euclidean distance matrix among all pairings or a sparse version for points within a fixed threshhold distance.

Usage

rdist(x1, x2)

fields.rdist.near(x1,x2, delta, max.points= NULL, mean.neighbor = 50)

Arguments

Details

More about fields.rdist.near:

The sparse version is designed to work with the sparse covariance functions in fields and anticipates that the full matrix, D is too large to store. The argument max.points is set as a default to nrow( x1)*100 and allocates the space to hold the sparse elements. In case that there are more points that are within delta the function stops with an error but lists the offending rows. Just rerun the function with a larger choice for max.points

It possible that for certain x1 points there are no x2 points within a distance delta. This situation will cause an error if the list is converted to spam format.

See Also

Exp.cov, rdist.earth, ind2spam, ind2full

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

set.seed(123)
x1<- matrix( runif( 20*2), 20,2)
x2<-  matrix( runif( 15*2), 15,2)

out3<- fields.rdist.near( x1,x2, delta=.5)
# out3 is a sparse structure in list format

# or to "save"  work space decrease size of temp array

 out3<- fields.rdist.near( x1,x2, delta=.5,max.points=20*15)

# explicitly reforming as a full matrix 
temp<- matrix( NA, nrow=out3$da[1], ncol= out3$da[2])
temp[ out3$ind] <- out3$ra 

#       or justuse 

  temp<- spind2full( out3)
  image( temp)

# this is  identical to 
 temp2<- rdist( x1,x2)
 temp2[ temp2<= .5] <- NA

Run the code above in your browser using DataLab