I'm trying to add the elements of an integer vector, which are nested in a two-level list.
I came up with this solution, but I think it's a little uncommon, so I am looking for another alternative:
df <- tibble(
a = list(list(c(1, 2), c(3, 4)), list(c(1, 2), c(3, 4)))
)
df %>%
mutate(
b = a %>% modify_depth(2, sum) %>% map(unlist)
)
which gives, and it's the right solution. But I am looking to use more of a map solution and less of modify.
# A tibble: 2 x 2
a b
<list> <list>
1 <list [2]> <dbl [2]>
2 <list [2]> <dbl [2]>
Solution in view mode:
