【发布时间】:2020-05-27 08:59:48
【问题描述】:
ggg <- data.frame(row.names=c("a","b","c","d","e"),var1=c("0","0","0","0","0"),var2=c("1","1","1","1","2"))
ggg_dist <- as.matrix(ggg) %>% as.dist(.)
In as.dist.default(.) : non-square matrix
class(ggg_dist)
[1] "dist"
ggg_dist
Warning message:
In df[row(df) > col(df)] <- x :
number of items to replace is not a multiple of replacement length
h_ggg <- hclust(ggg_dist,method="average")
Fehler in hclust(ggg_dist, method = "average") :
'D' must have length (N \choose 2).
我想用ggg 执行层次聚类。
ggg_dist 是由 class() 确认的距离,由 ggg 组成。我想用ggg_dist 进行层次聚类,但这不起作用。它显示上述错误。我该如何解决。
我尝试了 How to convert data.frame into distance matrix for hierarchical clustering? ,但是当我尝试调用 ggg_dist 时遇到同样的错误。
【问题讨论】: