I have a list list_tot that has nested lists.
I want to subset or create a new list that selects specific subsets based on the parameters specified, details follow:
List_1 <- list(a = matrix(5,2), b = matrix(5,7), c = matrix(5,9), d = matrix(5,3))
List_2 <- list(a = matrix(7,3), b = matrix(7,7), c = matrix(7,1), d = matrix(7,9))
List_3 <- list(a = matrix(5,2), b = matrix(5,7), c = matrix(5,9), d = matrix(5,3))
List_4 <- list(a = matrix(5,2), b = matrix(5,7), c = matrix(5,9), d = matrix(5,3))
List_5 <- list(a = matrix(5,2), b = matrix(5,7), c = matrix(5,9), d = matrix(5,3))
List_tot <- list(List_1, List_2, List_3, List_4, List_5)
that reads:
[[1]]
[[1]]$a
[,1]
[1,] 5
[2,] 5
[[1]]$b
[,1]
[1,] 5
[2,] 5
[3,] 5
[4,] 5
[5,] 5
[6,] 5
[7,] 5
[[1]]$c
[,1]
[1,] 5
[2,] 5
[3,] 5
[4,] 5
[5,] 5
[6,] 5
[7,] 5
[8,] 5
[9,] 5
[[1]]$d
[,1]
[1,] 5
[2,] 5
[3,] 5
[[2]]
[[2]]$a
[,1]
[1,] 7
[2,] 7
[3,] 7
[[2]]$b
[,1]
[1,] 7
[2,] 7
[3,] 7
[4,] 7
[5,] 7
[6,] 7
[7,] 7
[[2]]$c
[,1]
[1,] 7
...etc
I want to select:
- for each nested list only select list/matrix a, c, and d.
- for each nested list select two lists/matrices with the top number of rows.
So New_List_tot would have an output of:
that reads:
[[1]]
[[1]]$c
[,1]
[1,] 5
[2,] 5
[3,] 5
[4,] 5
[5,] 5
[6,] 5
[7,] 5
[8,] 5
[9,] 5
[[1]]$d
[,1]
[1,] 5
[2,] 5
[3,] 5
etc...
Any assistance would be helpful. All my attempts, attempts using plyer and dplyr, but with no success and very much stuck.