关于你对此有何评论,找到下面的代码:
恳求注意,代码可以在美观和效率方面得到改善。 进一步我用了第二个答案,否则它会是混乱。
# calculation of centroits based on:
# https://stat.ethz.ch/pipermail/r-help/2006-May/105328.html
cl <- hclust(dist(mydata, diag = TRUE, upper=TRUE))
cent <- tapply(mydata,
list(rep(cutree(cl, 5), ncol(mydata)), col(mydata)), mean)
dimnames(cent) <- list(NULL, dimnames(mydata)[[2]])
# add up cluster number and data and split by cluster
newdf <- data.frame(data=mydata, cluster=cutree(cl, k=5))
newdfl <- split(newdf, f=newdf$cluster)
# add centroids and drop cluster info
totaldf <- lapply(1:5,
function(i, li, cen) rbind(cen[i, ], li[[i]][ , -11]),
li=newdfl, cen=cent)
# calculate new distance to centroits and sort them
dist_to_cent <- lapply(totaldf, function(x)
sort(as.matrix(dist(x, diag=TRUE, upper=TRUE))[1, ]))
dist_to_cent
为重心的计算出的hclust
看到R-Mailinglist
你需要帮助瓦特/ R *命令*要得到这个工作,或W/* *的理解,将要使用的过程?这听起来像是一个关于统计的概念性问题,而不是关于R的编程问题。如果是这样,这个Q会更好地移植到[交叉验证](http://stats.stackexchange.com/)(即统计信息)。 SE)。 – gung
统计学上它非常清楚----我需要关于如何在R – hema
中做到这一点的帮助到目前为止你有什么R代码? –