library(purrr)
mm <- list(a = list(1:2), b = list(3:4), d = list(5:6))
nn <- list(a = list(7:8), b = list(9:10), d = list(11:12))
kk <- list(mm, nn)
kk1 <- kk |> purrr::map(~c(pluck(.,2),pluck(.,3)))
str(kk1)
#> List of 2
#> $ :List of 2
#> ..$ : int [1:2] 3 4
#> ..$ : int [1:2] 5 6
#> $ :List of 2
#> ..$ : int [1:2] 9 10
#> ..$ : int [1:2] 11 12
Created on 2021-09-15 by the reprex package (v2.0.0)
I still don't know exactly what you are looking for.
If it only amounts to selecting an 'arbitrary' number of elements then I would use [ ] as given below.
So no solution with pluck !
Explanation:
I thought that the kk2 solution could work, but I saw that the result was different.
In kk3 I corrected for this.
I hope this works for you. If not, let us know.
library(purrr)
mm <- list(a = list(1:2), b = list(3:4), c = list(5:6))
nn <- list(a = list(7:8), b = list(9:10), c = list(11:12))
kk <- list(mm, nn)
# old version
kk1 <- kk |> purrr::map(~c(pluck(.,2),pluck(.,3)))
str(kk1)
#> List of 2
#> $ :List of 2
#> ..$ : int [1:2] 3 4
#> ..$ : int [1:2] 5 6
#> $ :List of 2
#> ..$ : int [1:2] 9 10
#> ..$ : int [1:2] 11 12
# newer version but different result
kk2 <- kk |> purrr::map( ~(.[c(2,3)]) )
str(kk2)
#> List of 2
#> $ :List of 2
#> ..$ b:List of 1
#> .. ..$ : int [1:2] 3 4
#> ..$ c:List of 1
#> .. ..$ : int [1:2] 5 6
#> $ :List of 2
#> ..$ b:List of 1
#> .. ..$ : int [1:2] 9 10
#> ..$ c:List of 1
#> .. ..$ : int [1:2] 11 12
# newest version with same result as old version
kk3 <- kk |> purrr::map( ~(do.call(c,.[c(2,3)])) )
str(kk3)
#> List of 2
#> $ :List of 2
#> ..$ b: int [1:2] 3 4
#> ..$ c: int [1:2] 5 6
#> $ :List of 2
#> ..$ b: int [1:2] 9 10
#> ..$ c: int [1:2] 11 12
# same with three 'plucks'
kk4 <- kk |> purrr::map( ~(do.call(c,.[c(2,3,1)])) )
str(kk4)
#> List of 2
#> $ :List of 3
#> ..$ b: int [1:2] 3 4
#> ..$ c: int [1:2] 5 6
#> ..$ a: int [1:2] 1 2
#> $ :List of 3
#> ..$ b: int [1:2] 9 10
#> ..$ c: int [1:2] 11 12
#> ..$ a: int [1:2] 7 8
Created on 2021-09-17 by the reprex package (v2.0.0)