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对它存储的东西很聪明;它只需要下三角矩阵