以下代码给出了错误。是什么导致错误,我该怎么做才能解决?
# Determine number of clusters
wss <- (nrow(donnees.test$y - esvr1.pred) - 1) *
sum(apply(donnees.test$y - esvr1.pred, 2, var))
for (i in 2:15) wss[i] <- sum(kmeans(donnees.test$y - esvr1.pred,
centers=i)$withinss)
plot(1:15, wss, type="b", xlab="Number of Clusters",
ylab="Within groups sum of squares")
# K-Means Cluster Analysis
fit <- kmeans(donnees.test$y - esvr1.pred, 5) # 5 cluster solution
# get cluster means
aggregate(donnees.test$y - esvr1.pred, by=list(fit$cluster), FUN=mean)
# append cluster assignment
MainData <- data.frame(donnees.test$y - esvr1.pred, fit$cluster)
错误:
Error in apply(donnees.test$y - esvr1.pred, 2, var) :
dim(X) must have a positive length