Merge Two Lists in R

后端 未结 6 1110
南旧
南旧 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:48

    In general one could,

    merge_list <- function(...) by(v<-unlist(c(...)),names(v),base::c)
    

    Note that the by() solution returns an attributed list, so it will print differently, but will still be a list. But you can get rid of the attributes with attr(x,"_attribute.name_")<-NULL. You can probably also use aggregate().

提交回复
热议问题