I've got a nested list and I need to remove all the nodes/elements that have a specific name. For example, in the following defined R list(), I'd like to remove all nodes that have the name 'lol'. I note that it can appear at different levels of the hierarchy.
What's the best way to scan through the tree and remove those nodes?
tree <- list(
A = list(
A_1 = list(
A_1_1 = list(), A_1_2 = list()
),
lol = "haha"
),
B = list(
B_1 = list(
B_1_1 = list(), B_1_2 = list(), lol = "rofl"
)
)
)
I'd like to perform some action on the tree object so that result becomes:
$A
$A$A_1
$A$A_1$A_1_1
list()
$A$A_1$A_1_2
list()
$B
$B$B_1
$B$B_1$B_1_1
list()
$B$B_1$B_1_2
list()