R距离矩阵构建 [英] R distance matrix build
本文介绍了R距离矩阵构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
R的新手.我在R中有几个组件的坐标矩阵,看起来像:
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
...
我的问题是如何建立R中每个分量对的距离矩阵,例如:
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 ...
...
推荐答案
您会这样做
as.matrix(dist(Matrix))
然后:
rownames(DistMatrix) <- colnames(DistMatrix) <- rownames(Matrix)
这篇关于R距离矩阵构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文