我的 R 程序如下:
hcluster <- function(dmatrix) {
imatrix <- NULL
hc <- hclust(dist(dmatrix), method="average")
for(h in sort(unique(hc$height))) {
hc.index <- c(h,as.vector(cutree(hc,h=h)))
imatrix <- cbind(imatrix, hc.index)
}
return(imatrix)
}
dmatrix_file = commandArgs(trailingOnly = TRUE)[1]
print(paste('Reading distance matrix from', dmatrix_file))
dmatrix <- as.matrix(read.csv(dmatrix_file,header=FALSE))
imatrix <- hcluster(dmatrix)
imatrix_file = paste("results",dmatrix_file,sep="-")
print(paste('Wrinting results to', imatrix_file))
write.table(imatrix, file=imatrix_file, sep=",", quote=FALSE, row.names=FALSE, col.names=FALSE)
print('done!')
我的输入是一个距离矩阵(当然是对称的)。当我使用大于大约数千条记录的距离矩阵执行上述程序时(数百条记录都没有发生),它给了我错误消息:
Error in cutree(hc, h = h) :
the 'height' component of 'tree' is not sorted
(increasingly); consider applying as.hclust() first
Calls: hcluster -> as.vector -> cutree
Execution halted
我的机器有大约 16GB 的 RAM 和 4CPU,所以不会是资源问题。
任何人都可以让我知道有什么问题吗?谢谢!!