I need to compute every number in B
with every number in A
and every number in m0
with the formula in fun
. By applyingge <- lapply(B,fun)
I can compute every number in A
with every number in B
if m0 is a single number. How should I do if I have more than one m0
now as specified in the codes?
I think even for computing various B
and A
but single m0
, what I did here with lapply
in a function and then lapply
again is not a smart way.
The expected output is a list with values in B
computed with different numbers of A
and m0
.
This is the structure of ge
when m0
is a single value.
fun <- function (i){
res <- lapply(A, function(x){
g <- as.matrix (m0 * (-x * i))})}
ge <- lapply(B, fun)
m0 <- c(10,20)
A <- c(1,2)
B <- list(per1 = structure(list(t1 = c(1,2), t2 = c(3,4)), row.names = c(NA,
-2L), class = "data.frame"),
per2 = structure(list(t1 = c(10,20), t2 = c(30,40)), row.names = c(NA,
-2L), class = "data.frame"))