lolibility
lolibility

Reputation: 2187

R distance matrix build

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   ...
...

Upvotes: 0

Views: 2260

Answers (1)

Señor O
Señor O

Reputation: 17412

You would do

as.matrix(dist(Matrix))

Then:

rownames(DistMatrix) <- colnames(DistMatrix) <- rownames(Matrix)

Upvotes: 5

Related Questions