0

New to R. I have a matrix of coordinates of several components in R, looks like:

    x   y   z
C1  0.3 0.2 -1.2
C2  -1.5    0.7 0
C3  0.2 -0.75   0.22
...

My question is how to build a distance matrix of pairs of each components in R like:

    C1  C2  C3  ...
C1  0   0.2 0.7 ...
C2  0.2 0   1.2 ...
C3  0.7 1.2 0   ...
...
lolibility
  • 2,187
  • 6
  • 25
  • 45

1 Answers1

5

You would do

as.matrix(dist(Matrix))

Then:

rownames(DistMatrix) <- colnames(DistMatrix) <- rownames(Matrix)
Señor O
  • 17,049
  • 2
  • 45
  • 47