combine list elements based on element names

后端 未结 2 1677
说谎
说谎 2021-01-18 04:32

How to combine this list of vectors by elements names ?

L1 <- list(F01=c(1,2,3,4),F02=c(10,20,30),F01=c(5,6,7,8,9),F02=c(40,50))

So to g

2条回答
  •  不要未来只要你来
    2021-01-18 05:12

    You can achieve the same result using map function from purrr

    map(unique(names(L1)), ~ flatten_dbl(L1[names(L1) == .x])) %>%
      set_names(unique(names(L1)))
    

    The first line transforms the data by merging elements with matching names, while the last line renames new list accordingly.

提交回复
热议问题