passing arguments to a function in a single vector

匿名 (未验证) 提交于 2019-12-03 02:47:02

问题:

I created the following function:

nDone<- function (under,strike,ttoe,vol,rf,dy) pnorm(((log(under/strike)+   (rf-dy+(vol^2)/2)*ttoe)/(vol*(ttoe^0.5)))) 

Then I call the function with the following:

nDone(90,100,3,0.17,0.05,0) 

Result

[1] 0.6174643 

Ok so far were all good.

Now I create a vector with the same values in an object:

d<- c(90,100,3,0.17,0.05,0) 

and I try to call the function using the object.

nDone(d) 

And I get the following error.

Error in under/strike : 'strike' is missing 

What am I doing wrong and how to fix?

Thanks

RSG

回答1:

Try this

 do.call(nDone, as.list(d)) 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!