1

I have a list structure like

l = list(c("a","b"),list("a","b"),3)
l

# [[1]]
# [1] "a" "b"
#
# [[2]]
# [[2]][[1]]
# [1] "a"
#
# [[2]][[2]]
# [1] "b"
#
#
# [[3]]
# [1] 3

And I want to flatten this to

# [[1]]
# [1] "a" "b"
#
# [[2]]
# [1] "a"
#
# [[3]]
# [1] "b"
#
#
# [[4]]
# [1] 3

and I'm not sure how to proceed. As far as I'm aware this is beyond what unlist can handle. I found the answer in Python that I can follow, but I'm wondering if there's a better way to do it in R than copying to a new list.

Community
  • 1
  • 1
shadowtalker
  • 12,529
  • 3
  • 53
  • 96

0 Answers0