R distance matrix build

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-29 08:22:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!