I have N
lists that have some identical column names. Here is a MWE with two list:
ls <- list()
ls[[1]] <- list("a"=1:2,
"b"=20,
"c"=numeric(0))
names(ls[[1]]$a) <- c("a1", "a2")
ls[[2]] <- list("a"=3:4,
"b"=30,
"c"=1:4,
"d"="f")
names(ls[[2]]$a) <- c("a1", "a2")
Is it possible merge these into a resulting list lsRes
, where lsRes
has the following properties:
lsRes$a
contains two elements, where the first is the named vector c(1,2) (with names c(a1, a2)) and the second a named vector c(3,4) (with names (c(a1.a2)))lsRes$b
contains two elements, where the first is 20 and the second is 30lsRes$c
contains two elements, where the first is numeric(0) and the second is 1:4lsRes$d
contains two elements, where the first is NA and the second is "f"
I looked at this and this, but they describe different cases