我有一个列表列表的问题,我只想取消列出最底层的列表,然后合并在同一个列表中的所有元素。以下是示例:
alllist <- list(list(5,c(1,2)),list(3,c(4,5))) #A list of two sublists
alllist
[[1]]
[[1]][[1]]
[1] 5
[[1]][[2]]
[1] 1 2
[[2]]
[[2]][[1]]
[1] 3
[[2]][[2]]
[1] 4 5
#Unlist will unlist all levels
unlist(alllist, recursive = FALSE)
[[1]]
[1] 5
[[2]]
[1] 1 2
[[3]]
[1] 3
[[4]]
[1] 4 5
#But I want to keep the top level such that the result would be:
[1]
5 1 2
[2]
3 4 5
#I would also like to keep the order of the elements from the sublist while unlisting them