R

时间:2018-02-20 05:23:17

标签: function plot

如果x

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

我无法弄清楚如何对此进行问题排查,以及&#39; ifelse&#39;当我试图绘制它时,函数返回了一条黑色的黑线,这是我更喜欢避免的,所以这似乎是我最好的选择。

我非常感谢任何见解。

0 个答案:

没有答案
相关问题