如何在R中对列表列表进行子集?
例如我有这个清单:
[[6]]
[[6]][[1]]
[[6]][[1]][[1]]
[1] 111
[[6]][[2]]
[[6]][[2]][[1]]
[1] 1
[[6]][[2]][[2]]
[1] 11
[[6]][[3]]
[[6]][[3]][[1]]
[1] 11
[[6]][[3]][[2]]
[1] 1
[[6]][[4]]
[[6]][[4]][[1]]
[1] 1
[[6]][[4]][[2]]
[1] 1
[[6]][[4]][[3]]
[1] 1
我试图让列表的所有部分都有2个或更少的子列表。因此,在此示例中,输出将是前五个子列表,
[[6]]
[[6]][[1]]
[[6]][[1]][[1]]
[1] 111
[[6]][[2]]
[[6]][[2]][[1]]
[1] 1
[[6]][[2]][[2]]
[1] 11
[[6]][[3]]
[[6]][[3]][[1]]
[1] 11
[[6]][[3]][[2]]
[1] 1
答案 0 :(得分:2)
如果您的列表名为lst
,请尝试
lst[lengths(lst) <= 2]