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也需要衔接在上一句的}后面


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM