Subset the i-th elements of a nested list

Code

Select all i-th elements of a nested list x, in R language:

#!/usr/bin/R

lapply(x, `[[`, i)

This is useful after having used the stringr::str_split function…

Input

Structure of the input list x:

x
├── A
│   ├── A_1
│   ├── A_2
│   ├── A_3
│   └── A_4
├── B
│   ├── B_1
│   ├── B_2
│   ├── B_3
│   └── B_4
└── C
    ├── C_1
    ├── C_2
    ├── C_3
    └── C_4

Output

Structure, after execution of the command (i = 2):

x
├── A
│   └── A_2
├── B
│   └── B_2
└── C
    └── C_2