I have lists v1 and v2 with the same names:
v1: structure(list(ID = c("A1"), Name = c("A2"),.Names = c("ID", "Name")
...
v2: structure(list(ID = c("B1"), Name = c("B2"),.Names = c("ID", "Name")
I want to concatenate the lists, while keeping the names, i.e. to get something like:
v12: structure(list(ID = c("A1","B1"), Name = c("A2","B2"),
.Names = c("ID", "Name")
Manual concatenation works:
v12<-cbind(Map(c, v1, v2))
But, if v1 and v2 are results of applying lapply(), and are stored in a list themselves, the similar logic does not seem to work:
v<-lapply(...)
v12<-cbind(Map(c,v))
What is the best way to automate the process? For example:
v1 <- structure(list(ID = c("A1"), Name = c("A2")),.Names = c("ID", "Name"))
v2 <- structure(list(ID = c("B1"), Name = c("B2")),.Names = c("ID", "Name"))
v <- list(v1, v2)
k<-t(mapply(c, v))
results in:
ID Name
A1 A2
B1 B2
not in:
ID Name
"A1","B1" "A2","B2"