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