km <- kmeans(iris,3)
predict.kmeans <-
function(km, data)
{k <- nrow(km$centers)
n <- nrow(data)
d <- as.matrix(dist(rbind(km$centers, data)))[-(1:k),1:k]
out <- apply(d, 1, which.min)
return(out)}
predict.kmeans(km,iris[1,])
# Error:apply(d, 1, which.min) : dim(X) must have a positive length
我的简单代码在这里有一些问题,它有什么问题?