Error .. missing value where TRUE/FALSE needed

后端 未结 3 607
伪装坚强ぢ
伪装坚强ぢ 2021-01-28 19:34

I have been trying to run this code (below here) and I have gotten that message \"Error in if (temp[ii] == 0) { : missing value where TRUE/FALSE needed\"...

temp         


        
3条回答
  •  旧巷少年郎
    2021-01-28 20:29

    Your problem is that temp[ii] is returning NA because ii goes out of bounds:

    ii = i + 1:tm     #Your declaration for ii
    ii = 1:tm + 1:tm  #Evaluates to
    

    So ii will definitely be larger than tm (and therefore length(temp) at some point.

    In order to better understand/debug for loops, consider printing just the indices:

    for(i in 1:tm)
    {
        print(i)
        for(ii in i + 1:tm)
            print(ii)
    }
    

提交回复
热议问题