R 多if语句中的错误
我正在用R编写以下代码,但它给了我一个错误R 多if语句中的错误,r,if-statement,R,If Statement,我正在用R编写以下代码,但它给了我一个错误 S=function(x,a){ if(x<=a) {return (g)} else if (a < x <= b) {return(h)} > Error: unexpected '<=' in: > " > else if (a < x <=" > else (return(i)) > } S=函数(x,
S=function(x,a){
if(x<=a) {return (g)}
else
if (a < x <= b) {return(h)}
> Error: unexpected '<=' in:
> "
> else if (a < x <="
> else (return(i))
> }
S=函数(x,a){
如果(x“
>否则如果(a
S=function(x, a, b){
if (x <= a){
return(a)
}
else if ((a < x) && (x <= b)){ # break up the compound into two tests
return(a)
}
else{
return(a)
}
}
也许你的意思是(为什么你要比较x和a两次?为什么这个标签上有“R”标记?这看起来像javascript之类的东西。
> S(1,2,3)
[1] 2