【问题标题】:Hierarchical Clustering given distance matrix给定距离矩阵的层次聚类
【发布时间】:2016-08-21 18:21:18
【问题描述】:

给定一个距离矩阵

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.

【问题讨论】:

    标签: r hierarchical-clustering


    【解决方案1】:

    你需要用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 在存储内容方面很聪明;它只需要下三角矩阵。

    【讨论】:

      猜你喜欢
      • 2014-10-24
      • 2014-07-28
      • 2012-09-05
      • 2019-01-11
      • 2020-01-23
      • 2015-09-14
      • 2016-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多