Learn R Programming

pcds (version 0.1.2)

Dist: The distance between two vectors, matrices, or data frames

Description

Returns the Euclidean distance between x and y which can be vectors or matrices or data frames of any dimension (x and y should be of same dimension).

This function is different from the dist function in the stats package of the standard R distribution. dist requires its argument to be a data matrix and dist computes and returns the distance matrix computed by using the specified distance measure to compute the distances between the rows of a data matrix (S-Book:1998;textualpcds), while Dist needs two arguments to find the distances between. For two data matrices \(A\) and \(B\), dist(rbind(as.vector(A),as.vector(B))) and Dist(A,B) yield the same result.

Usage

Dist(x, y)

Arguments

x, y

Vectors, matrices or data frames (both should be of the same type).

Value

Euclidean distance between x and y

References

See Also

dist from the base package stats

Examples

Run this code
# NOT RUN {
B<-c(1,0); C<-c(1/2,sqrt(3)/2);
Dist(B,C);
dist(rbind(B,C))
dist(rbind(as.vector(B),as.vector(C)))
Dist(B,B);

x<-runif(10)
y<-runif(10)
Dist(x,y)

xm<-matrix(x,ncol=2)
ym<-matrix(y,ncol=2)
Dist(xm,ym)
dist(rbind(as.vector(xm),as.vector(ym)))

Dist(xm,xm)

dat.fr<-data.frame(b=B,c=C)
Dist(dat.fr,dat.fr)
Dist(dat.fr,cbind(B,C))

# }

Run the code above in your browser using DataLab