问题
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 ...
...
回答1:
You would do
as.matrix(dist(Matrix))
Then:
rownames(DistMatrix) <- colnames(DistMatrix) <- rownames(Matrix)
来源:https://stackoverflow.com/questions/13843048/r-distance-matrix-build