Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 多if语句中的错误_R_If Statement - Fatal编程技术网

R 多if语句中的错误

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,

我正在用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,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