R语言中else if 常见错误

Posted yuvejxke

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了R语言中else if 常见错误相关的知识,希望对你有一定的参考价值。

    if (0.1>RATE=>0){wthistory=0}
    else if(0.3>RATE=>0.1){wthistory=5}
    else if(0.5>RATE=>0.3){wthistory=10}
    else if(0.7>RATE=>0.5){wthistory=15}
    else if(0.9>RATE=>0.7){wthistory=15}
    else{wthistory=30}

R语言中支持 else if 的判断,但是上面的写法是错误的

 

技术图片

 

 R无法判断 if 对应的else 在何处结尾

 

修改如下

 

if (0.1>RATE&RATE>=0){wthistory=0
} else if(0.3>RATE&RATE>=0.1){wthistory=5
} else if(0.5>RATE&RATE>=0.3){wthistory=10
} else if(0.7>RATE&RATE>=0.5){wthistory=15
} else if(0.9>RATE&RATE>=0.7){wthistory=15
} else{wthistory=30}

这里的每个else if 都接在上一句的}后面

注意最后的else也需要衔接在上一句的}后面

以上是关于R语言中else if 常见错误的主要内容,如果未能解决你的问题,请参考以下文章