下面是书上代码,自己在运行过程中报错,也画不出书上的图示。本人纯小白一个,请大神不吝指导。
library(flexclust)
data(nutrient)
head(nutrient, 4)
d <- dist(nutrient) #dist(x, method=)计算各个观测之间的距离,默认欧氏距离
as.matrix(d)[1:4,1:4]
str(d)
class(d)
row.names(nutrient) <- tolower(row.names(nutrient))
nutrient.scaled <- scale(nutrient)
d <- dist(nutrient.scaled)
fit.average <- hclust(d, method="average")
library(ggplot2)
library(ggdendro)
ggdendrogram(fit.average) + labs(title="Average Linkage Clustering")
library(NbClust)
library(factoextra)
nc <- NbClust(nutrient.scaled, distance="euclidean",
min.nc=2, max.nc=15, method="average") [size=14.6667px]这一步运行后报错:I[size=14.6667px]n pf(beale, pp, df2) : 产生了NaNs
fviz_nbclust(nc)
[size=14.6667px]这一步运行后报错:[size=14.6667px]Error in if (class(best_nc) == "numeric") print(best_nc) else if (class(best_nc) == :
the condition has length > 1
这是书上的代码和截图,实际操作的时候会报错,问题出在哪儿呢?