1、聚类分析
使用的是距离矩阵
D=dist(iris)
hc=hcclust(D,method="single") #method方法默认是complete,最长距离
plot(hc)
2、K-means(K均值聚类或K近邻聚类)
使用的是普通矩阵
set.seed(123)
km=kmeans(chart,5)
kc=km$cluster #cluster是km的一列值,用$可以将其单独读取出来
实验问题:
报错信息:
Warning message:
In dist(effection) : NAs introduced by coercion
> effection=read.xlsx('D:/大三下/多元统计分析R语言/实验报告/3-6.xlsx',rowNames=T,1)
> hc=hclust(dist(effection),method = "ward.D2")
Warning message:
In dist(effection) : NAs introduced by coercion
说明实验数据有问题,有两种可能,两种处理方法:
1、导入数据时,第一列无关数据(eg:序号)也加入了运算
——>直接在excel表中删除无关列
——>或者在导入数据时,设置以下rowNames=T,让导入的第一列设置为title&#