1

Say I have the following:

a <- c(7,1,9,1,3)
b <- c(4,9,1,3,1)
c <- c(9,1,7,2,2)

I know I can get the Euclidean distance of any two of the vectors by doing the following:

dist(rbind(a, b))

Is there a way in R I can get the distances of all possible combinations (i.e, A & B, A & C and B & C), in a single statement?

Randy Minder
  • 47,200
  • 49
  • 204
  • 358

1 Answers1

4

Yes. If you run dist(rbind(a,b,c)) the results are a table of euclidean distances.

Eli Sadoff
  • 7,173
  • 6
  • 33
  • 61