apply()中的错误:dim(X)必须具有正长度

时间:2014-01-27 19:35:06

标签: r k-means

以下代码给出了错误。是什么导致错误,我该怎么做才能解决?

# 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

0 个答案:

没有答案