Merge Two Lists in R

后端 未结 6 1076
南旧
南旧 2020-11-28 22:52

I have two lists

first = list(a = 1, b = 2, c = 3)
second = list(a = 2, b = 3, c = 4)

I want to merge these two lists so the final product

6条回答
  •  攒了一身酷
    2020-11-28 23:39

    merged = map(names(first), ~c(first[[.x]], second[[.x]])
    merged = set_names(merged, names(first))
    

    Using purrr. Also solves the problem of your lists not being in order.

提交回复
热议问题