错误调试{:缺少值,需要TRUE/FALSE [英] Error Debug { : missing value where TRUE/FALSE needed

查看:340
本文介绍了错误调试{:缺少值,需要TRUE/FALSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试运行此代码(在下面),但出现此错误:

I have been trying to run this code (below here) and I have getting this error:

for(i in 1:length(qid2))
{
  for(j in 1:length(qid))
  {
    if (qid2[i]==qid[i])
    {
        correct.option[i] = aid[j+cid[j]]
        print(correct.option[i])
    }
  }
}

if(qid2 [i] == qid [i]){时出现错误:需要TRUE/FALSE的缺失值

Error in if (qid2[i] == qid[i]) { : missing value where TRUE/FALSE needed

推荐答案

可能是因为qid2qid的长度不同,所以在某些点上i大于较短的长度,因此比较涉及不存在的元素.也许您打算比较qid2[i]==qid[j]?下面的cat()语句是如何调试此类事件的示例.

Probably because qid2 and qid are different lengths, so at some point i is larger than the shorter length, so that the comparison involves an element that doesn't exist. Perhaps you meant to compare qid2[i]==qid[j] ? The cat() statement below is an example of how you would debug this sort of thing.

qid2 <- 1:3
qid <- 1:2
for (i in 1:length(qid2)) {
   for(j in 1:length(qid)) {
       cat(i,j,qid[i],qid2[i],"\n")
       if (qid2[i]==qid[i]) {
       }
   }
}
## 1 1 1 1 
## 1 2 1 1 
## 2 1 2 2 
## 2 2 2 2 
## 3 1 NA 3 
## Error in if (qid2[i] == qid[i]) {
##     (from #4) : missing value where TRUE/FALSE needed

这篇关于错误调试{:缺少值,需要TRUE/FALSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆