我正在处理一个复杂的项目,每次我都需要使用上一次运行函数的结果来运行函数.为了让我的观点更清楚,假设我有一个向量x
和一个函数myfunc
.然后,我需要使用向量x
来运行myfunc
.然后,我获取函数的输出,并将它们作为同一函数的参数再次插入.我需要自动重复几次.
例如,
x <- c(1,2,3)
myfunc <- function(x){
res <- 2*x
return(res)
}
然后,
x <- myfunc(x)
> x
[1] 2 4 6
x <- myfunc(x)
> x
[1] 4 8 12
How can I do this automatically (repeat for, say, 5
times)? In the end, I need the result of the final run only. 例如, the result of the fifth run.