0
votes

I've got this code in 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
        }

j <= k in the while statement is returning this error:

missing value where TRUE/FALSE needed.

group_IDs is not null and it actually contains the value 8 in this case. It seems to get into the loop and crash at the second round.

2
Can you show us what group_IDs looks like? - rosscova
What does nrow(group_IDs) return? - rosscova
nrow(group_IDs) is a vector that in this case contains just one value. The value is number 8 but it could be any series of numbers. - Dario Federici

2 Answers

0
votes

You can get around the indexing issues using for, e.g.:

for (ID in group_IDs) {}

This, of course, assumes that group_IDs is a vector of values.

Note: Your code shows the following inside the loop group_IDs$Group_ID[j] which implies something other than a vector; perhaps you meant group_IDs[j]?

0
votes

Since group_ IDsis a vector, try length(group_IDs) instead of nrow. A vector doesn't have rows, so the equivalent is length.

Here's what I suspect is happening:

> group_IDs <- 8
> nrow(group_IDs)
NULL