I'm wondering if it's possible to apply purrr::pmap
(purrr::map2
?) combined with purrr::map_depth
.
Let's say I have two lists with exact same structure with multiple nested lists, defined as:
l1 <- list(
list(0.0132),
list(
list(0.033, 0.066)
),
list(
list(
list(0.165, 0.11, 0.06),
list(0.165, 0.22, 0.12)
)
)
)
l2 <- list(
list(0.6),
list(
list(0.75, 0.1)
),
list(
list(
list(0.65, 0.71, 0.16),
list(0.25, 0.98, 0.22)
)
)
)
Is it possible to combine purrr's
functions, (pmap
, map_depth
, vec_depth
, etc) to apply some function but taking into account different depths?
Let's suppose I want to get the product l1
*l2
of each element between lists (e.g. 0.0132*0.6
, 0.033*0.75
, ...). Using same principle as I'd apply with map2
, I have tried passing 3 arguments to pmap, l1
, l2
, vdepth
, but I'm not able to get desired results.
vdepth <- map(l1, vec_depth)
pmap(list(l1, l2, vdepth), function(a, b, d) map_depth(c(a, b), d - 1, ~ FUN))
Final result should have same structure as any of the lists used as inputs.
PS: Not very fan of unlist
and trying to stick to purrr
's functions...