data<-read.table("pcadata.txt",header=T,row.names=1)
dist.r=dist(data,method="euclidean") #euclidean 欧式距离
hc.r = hclust(dist.r, method = "ward")
垂直树
plot(hc.r, hang = -1,labels=NULL)
水平树
plot(as.dendrogram(hc.r),horiz=T)
result = cutree(hc.r,k=4)
网友评论