如果x 然后当我尝试用 我得到了 我无法弄清楚如何对此进行问题排查,以及&#39; ifelse&#39;当我试图绘制它时,函数返回了一条黑色的黑线,这是我更喜欢避免的,所以这似乎是我最好的选择。 我非常感谢任何见解。g <- function(x) {
if (x < 0)
-3 # first component
else if (x >= 0 & x <= 5)
(1/3) * x #second component
else
4*x # third component
}
plot(g, -20, 20)
Error in curve(expr = x, from = from, to = to, xlim = xlim, ylab = ylab, :
'expr' did not evaluate to an object of length 'n'
In addition: Warning message:
In if (x < 0) -3 else if (x >= 0 & x <= 5) (1/3) * x else 4 * x :
the condition has length > 1 and only the first element will be used