c1r1

mail@pastecode.io avatar
unknown
r
2 years ago
461 B
0
Indexable
Never
setwd("D:/CollegeAffairs/22秋/应用多元分析/第五次实验")
rawdata <- read.xlsx("exec6.3.xlsx", sheetIndex = 1)
rownames(rawdata) <- rawdata[,1]
rawdata <- rawdata[,-1]
D <- 1-rawdata
D <- as.dist(D, diag = TRUE)

#最长距离法
hc1 <- hclust(D, "complete")
cbind(hc1$merge, hc1$height) 
plot(hc1, hang = -1)

#类平均距离法
hc2 <- hclust(D, "average")
cbind(hc2$merge, hc2$height) 
plot(hc2, hang = -1)
rect.hclust(hc2, k = 2)