简体   繁体   English

距离矩阵到dist元素

[英]Distance matrix to dist element

New to R here. R的新手。 I have computed a distance matrix over, say, points a, b, c: 我已经计算了例如点a,b,c的距离矩阵:

(a,a) = 0;
(a,b) = 1;
(a,c) = 5;
(b,a) = 1;
(b,b) = 0;
(b,c) = 7;
(c,a) = 5;
(c,b) = 7;
(c,c) = 0;

And I want to use a function that expects the 'dist' R element. 我想使用一个需要'dist'R元素的函数。 My distance function is the result of a computation on the items' coordinates, but it's not a standard computation, so I can't create the dist element using the dist constructor, which expects only several predefined distance measures. 我的距离函数是对项目坐标进行计算的结果,但这不是标准计算,因此我无法使用dist构造函数创建dist元素,该构造函数仅需要几个预定义的距离度量。

Bottom line is that I want to create the dist element out of the matrix that I have computed. 最重要的是,我想从已计算的矩阵中创建dist元素。

Appreciate your help! 感谢您的帮助!

You can create a distance class object from a matrix 您可以从矩阵创建距离类对象

Just create the matrix and use as.dist 只需创建矩阵并使用as.dist

eg 例如

 as.dist(matrix( c(0, 1, 5, 1, 0, 7, 5, 7, 0), ncol=3))


  1 2
2 1  
3 5 7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM