Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 给定距离矩阵的层次聚类_R_Hierarchical Clustering - Fatal编程技术网

R 给定距离矩阵的层次聚类

R 给定距离矩阵的层次聚类,r,hierarchical-clustering,R,Hierarchical Clustering,给定一个距离矩阵 d = matrix(c(0,2.5,4.5,2.5,0,3.4,4.5,3.4,0), nrow=3), 如何使用R进行分层聚类?使用 hclust(d) 这是给我的错误 Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : missing value where TRUE/FALSE needed. 您需要将其转换为具有dist的对象 d1 = as.

给定一个距离矩阵

d = matrix(c(0,2.5,4.5,2.5,0,3.4,4.5,3.4,0), nrow=3),
如何使用R进行分层聚类?使用

hclust(d)
这是给我的错误

Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") :  missing value where TRUE/FALSE needed.

您需要将其转换为具有
dist
的对象

d1 = as.dist(d)
hclust(d1)

如果您检查
d1

R> str(d1)
Class 'dist'  atomic [1:3] 2.5 4.5 3.4
  ..- attr(*, "Size")= int 3
  ..- attr(*, "call")= language as.dist.default(m = d)
  ..- attr(*, "Diag")= logi FALSE
  ..- attr(*, "Upper")= logi FALSE 
你可以看到R对它存储的东西很聪明;它只需要下三角矩阵