I was wondering if there\'s a simple way to combine the functions of rapply( , how = \"replace\")
and mapply()
, in order to use mapply()
You can use Map
recursively (twice) to accomplish this:
Map(function(i, j) Map(function(x, y) x + y, i, j), A, B)
[[1]]
[[1]][[1]]
[1] 2 4 6
[[1]][[2]]
[1] 4 6 8
[[2]]
[[2]][[1]]
[1] 8 6 4
[[2]][[2]]
[1] 6 4 2
To use mapply
, you would need simplify=FALSE, but that is the default for Map
. The outer list elements are fed to the first Map
and the inner list elements are fed to the second Map
.