-4

r-studio 一直告诉我我的代码中有一个意外的“}”,但不明白为什么。我已经检查了每个括号两次...

    for (i in 1:100){
        for(j in 1:15){
            if (s2[i] == sensoren[j,1] && s3[i] == sensoren[j,2] && s4[i] ==   sensoren[j,3]){ 
                print(sensoren[j,5])
                i <- i + 1
                } else              
                j <- j + 1
        }
    }
4

2 回答 2

2

Using (since you didn't give us data; this is considered unkind):

s2 <- s3 <- s4 <- 1:100
sensoren <- mtcars

## > for (i in 1:100){
## +        for(j in 1:15){
## +            if (s2[i] == sensoren[j,1] && s3[i] == sensoren[j,2] && s4[i] ==   sensoren[j,3]){ 
## +                print(sensoren[j,5])
## +                i <- i + 1
## +                } else             
## +                j <- j + 1
## +        }
## +     }
## > }
## Error: unexpected '}' in "}"

## And then:

## > for (i in 1:100){
## +        for(j in 1:15){
## +            if (s2[i] == sensoren[j,1] && s3[i] == sensoren[j,2] && s4[i] ==   sensoren[j,3]){ 
## +                print(sensoren[j,5])
## +                i <- i + 1
## +                } else {            
## +                j <- j + 1
## +        }
## +     }
## + }

Try a { after the else

于 2013-05-05T17:35:18.663 回答
0

这几乎可以肯定是因为您的完整代码在某处有一个不平衡的“(”或“[”,因此“}”出现在非法位置。

于 2013-05-05T16:20:58.220 回答