Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要多次重复一个函数,不同的参数在迭代中保持不变。为此,我想创建一个参数列表(或向量),然后将该列表插入到函数中。
例如:
q<-c("l,a,b,s") genericfunction<-function(q){ }
等效的代码当然是
genericfunction<-function(l,a,b,s){ }
任何帮助或建议将不胜感激。
在我看来,你在追求do.call。
do.call
genericfunction <- function(l, a, b, s){ l+a+b+s } args <- list(l=1, a=3, b=345, s=-4) do.call(genericfunction, args) [1] 345
您是否检查过 get() 和 assign() 函数 - 它们可能会完成您所追求的。你能扩展你的例子吗?