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
sapply(unique(names(L1)), function(x) unname(unlist(L1[names(L1)==x])), simplify=FALSE)
$F01
[1] 1 2 3 4 5 6 7 8 9
$F02
[1] 10 20 30 40 50
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.