This code produces an error:
Error in while (diff < limit) { : missing value where TRUE/FALSE
needed
i <- 1
j <- 1
limit <- 0.05
diff <- 0
ppm <- rep(NA,20)
while(i[1]<=nrow(list))
{
while(diff < limit) ##This is where the error is occurring
{
if(j==0)
ppm <- rep(NA,length(ppm))
ppm[j] <- list$ppm[i]
j <- j+1
if(j > 1)
diff <- ppm[j]-ppm[j-1]
}
print(ppm)
}
Now i have found that this is usually because the condition in while is evaluating to NA and hence while cannot check for TRUE/FALSE. But in this case i really don’t see what the error is.
On your first time through the
whileloop:jis 1,ppm[1]gets set to theith (first) element oflist$ppmjgets incremented to 2jis now > 1, so you take the difference betweenppm[2]which is stillNA, sinceppmwas initialized toNAandppm[2]hasn’t been touched yet andppm[1]; the result isNANow go back to the top of the
whileloop and comparediff(nowNA) withlimit(fixed at 0.05) … boom.