here is my minimal example:
calA_fun <- function(list_A){
for (k in 1:length(list_A)){
out_level = list()
out_level[[k]] <- unlist( lapply(list_A[[k]], sqrt) )
for (j in 1:length(list_A[[k]]) ){
out_level_level = list()
out_level_level[[j]] <- lapply(list_A[[k]][[j]], function(x) x+ out_level[[k]] )
print(out_level_level[[j]])
}
}
}
list_A <- list(aa = c(1, 2, 4), bb = c(6,2))
calA_fun(list_A)
I am rewriting this function using apply() family or map() to replace for loop but I don't know if it is possible since j is nested into k so it is a hierarchical structure.
Thanks!