This is a simple version of purrr::transpose
, only for lists with 2 levels.
Examples
# create a 2-deep, 2 levels in first, 3 levels in second
a <- list(a = list(d = 1, e = 2:3, f = 4:6), b = list(d = 5, e = 55))
invertList(a) # creates 2-deep, now 3 levels outer --> 2 levels inner
#> $d
#> $d$a
#> [1] 1
#>
#> $d$b
#> [1] 5
#>
#>
#> $e
#> $e$a
#> [1] 2 3
#>
#> $e$b
#> [1] 55
#>
#>
#> $f
#> $f$a
#> [1] 4 5 6
#>
#> $f$b
#> NULL
#>
#>