R:从所有嵌套列表中删除相同的条目
给定如下嵌套列表:R:从所有嵌套列表中删除相同的条目,r,nested-lists,R,Nested Lists,给定如下嵌套列表: list_original <- list(list1 = list(foo = 1, bar = 2), list2 = list(foo = 1, bar = 2)) 实际上,我需要从100000多个嵌套列表中删除该条目 谢谢 使用lappy将每个列表中的foo设置为NULL: 代码: list_original <- list(list1 = list(foo = 1, bar = 2), list2 = list(foo = 1, bar = 2)) l
list_original <- list(list1 = list(foo = 1, bar = 2), list2 = list(foo = 1, bar = 2))
实际上,我需要从100000多个嵌套列表中删除该条目
谢谢 使用
lappy
将每个列表中的foo
设置为NULL
:
代码:
list_original <- list(list1 = list(foo = 1, bar = 2), list2 = list(foo = 1, bar = 2))
list_final <- lapply(list_original, function(x) {
x[["foo"]] <- NULL
x
})
list_final
$list1
$list1$bar
[1] 2
$list2
$list2$bar
[1] 2
使用
lappy
将每个列表中的foo
设置为NULL
:
代码:
list_original <- list(list1 = list(foo = 1, bar = 2), list2 = list(foo = 1, bar = 2))
list_final <- lapply(list_original, function(x) {
x[["foo"]] <- NULL
x
})
list_final
$list1
$list1$bar
[1] 2
$list2
$list2$bar
[1] 2