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

posted @ 2020-02-22 11:26  余者皆可  阅读(2005)  评论(0)    收藏  举报