【发布时间】:2020-03-02 21:55:46
【问题描述】:
尝试创建一个可以保存“分数”向量的函数,然后该函数将确定分数的定性评级。我已经多次重新排列我的括号,但我仍然得到这些错误。 “else”也会出错。
credit_fun <- function(scores){
if (scores>300 & scores<579)(incbounds = TRUE){
'Very Poor';
} else if (scores>580 & scores<669)(incbounds = TRUE){
'Fair';
} else if (scores>670 & scores<739)(incbounds = TRUE){
'Good';
} else if (scores>740 & scores<799)(incbounds = TRUE){
'Very Good';
} else if (scores>800 & scores<850)(incbounds = TRUE){
'Exceptional'}
}
【问题讨论】:
-
so if ((scores>300 & scores
-
啊好吧,让我试试
-
好的,意外的 'else' 消失了,但每行仍然出现“意外的 '{'
-
对此不完全确定,我的同行也包括在内。我认为这是为了确保值保持在范围内?如果我在 if 语句中有约束,是否没有必要?
-
我放弃了 incbounds,它确实摆脱了错误。它只返回向量中的第一个值。如何调整函数以使其与各种长度的向量兼容?
标签: r if-statement curly-braces