Sar*_*lle 2 variables r function variable-assignment
问题出在标题中.我想做这样的事情:
myfunc<- pexp
plot(function(x) myfunc(x, 0.5))
Run Code Online (Sandbox Code Playgroud)
我想在我的脚本中调用几个作为参数给出的函数.我想使用foreach而不是一堆if-then-else语句:
假设我以这种方式调用我的脚本:
R --slave -f script.R --args plnorm pnorm
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情:
#only get parameters after --args
args<-commandArgs(trailingOnly=TRUE)
for i in args {
plot(function(x) i(x,param1,param2))
}
Run Code Online (Sandbox Code Playgroud)
用于get
在给定包含其名称的字符串的情况下检索对象.在这种情况下,您还可以使用getFunction
特定版本来检索功能.
for f in args {
f <- getFunction(f)
plot(function(x) f(x, param1, param2))
}
Run Code Online (Sandbox Code Playgroud)