【发布时间】:2016-11-06 18:44:43
【问题描述】:
我在 R 中有这段代码:
j <- 1
k <- nrow(group_IDs)
while (j <= k)
{
d_clust <- Mclust(Customers_Attibutes_s[which (Customers_Attibutes_s$Group_ID == group_IDs$Group_ID[j]),3:7], G=2:7)
temp <- cbind(Customers_Attibutes[which (Customers_Attibutes$Group_ID == group_IDs$Group_ID[j]),], as.data.frame (predict.Mclust(d_clust, Customers_Attibutes[which(Customers_Attibutes$Group_ID == group_IDs$Group_ID[j]), 3:7]))[1])
temp_ <- rbind(temp,temp_)
j <- j+1
}
while 语句中的j <= k 返回此错误:
需要 TRUE/FALSE 的地方缺少值。
group_IDs 不为空,在这种情况下它实际上包含值 8。
好像进入了循环,在第二轮就崩溃了。
【问题讨论】:
-
你能告诉我们group_IDs是什么样的吗?
-
nrow(group_IDs)返回什么? -
nrow(group_IDs) 是一个向量,在这种情况下只包含一个值。该值是数字 8,但它可以是任何数字序列。