我已经在 R 中编写了这个简单的函数
> w=c(0.005,0.005,0.006,0.01,0.88,0.03,0.01,0.01,0.005,0.34,0.05)
> trial<- function(a) {sum(a-w)}
> trial(0.1)
[1] 0.996
如您所见,如果我为 a 输入一个值,则此函数可以正常工作,但是我想绘制它,并且与不涉及 sum 的函数不同,以下内容不起作用:
> plot(trial)
给我错误:
> Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
In addition: Warning message:
In a - w : longer object length is not a multiple of shorter object length
我知道 R 要求一个长度为 11 的向量,但是有没有办法绘制这个函数?