rapply传入列表时出错,无法读入传入的参数

rapply传入列表时出错,无法读入传入的参数,r,lapply,R,Lapply,这里有一个有效的例子 当我运行以下命令时: example <- list() example[[1]] <-matrix(c(1000000,2000000,2000000,5000000), nrow=4, ncol = 1) example[[2]] <-matrix(c(1500000,2200000,2200000,5000000, 3500000), nrow=5, ncol = 1) custom_func=function(X, O_low, O_high,

这里有一个有效的例子

当我运行以下命令时:

example <- list()
example[[1]] <-matrix(c(1000000,2000000,2000000,5000000), nrow=4, ncol = 1)
example[[2]] <-matrix(c(1500000,2200000,2200000,5000000, 3500000), nrow=5, ncol = 1)

custom_func=function(X, O_low, O_high, A_low, A_high){
  d_vec = vector(length = 1)
  D_occ = pmin(pmax(X-O_low,0),O_high)
  TOTAL_D = pmin(pmax(sum(D_occ)-A_low,0),A_high)
  d_vec[i]=TOTAL_D
  return(mean(d_vec, na.rm=TRUE))
}

rapply(example, custom_func(O_low=1000000, O_high=3000000, A_low=5000000, A_high=25000000), how='list')
X应该是一个
示例[[1]]
,然后是
示例[[2]]
,但我实际上如何传递它呢? 最终,O_low、O_high、A_low、A_high都将是循环值,并且示例的大小会有所不同

如果我做了下面这样的事情,它似乎会自动检测到我需要传递的内容。。。
rapply(例如,mean,how='list')

如果我们删除
d\u-vec[i]
中的
[i]
,如果我们使用匿名函数调用(
function(x)
)或者只指定参数和函数而不使用
()

使用匿名函数(lambda函数)

或者没有lambda的电话

rapply(example, custom_func, O_low=1000000, 
         O_high=3000000, A_low=5000000, A_high=25000000, how='list')
#[[1]]
#[1] 0

#[[2]]
#[1] 3400000

如果我们删除
d_-vec[i]
中的
[i]
,如果我们使用匿名函数调用(
function(x)
),或者只指定参数和函数而不使用
()

使用匿名函数(lambda函数)

或者没有lambda的电话

rapply(example, custom_func, O_low=1000000, 
         O_high=3000000, A_low=5000000, A_high=25000000, how='list')
#[[1]]
#[1] 0

#[[2]]
#[1] 3400000

什么是
i
d\u-vec[i]=
什么是
i
d\u-vec[i]=
rapply(example, function(x) custom_func(x, O_low=1000000, 
         O_high=3000000, A_low=5000000, A_high=25000000), how='list')
#[[1]]
#[1] 0

#[[2]]
#[1] 3400000
rapply(example, custom_func, O_low=1000000, 
         O_high=3000000, A_low=5000000, A_high=25000000, how='list')
#[[1]]
#[1] 0

#[[2]]
#[1] 3400000