1

I have two list with sublists (R). I would like to create just one list and concatenate the element of the first sublist in list1 with the element of the first sublist in list2, the element of the second sublist in list1 with the element of the second sublist in list 2, and so on. I did it using a for loop, is there a smarter way to do it?

list1<-list(A=c(1,2,3),
  B=c(2,3),
  C=c(7,8))

list2<- list(A=c(3,8,9),
      B=c(3), 
      C=c(27,80,56))

list_n <- vector('list',length(list2))
for(i in 1:length(list1)){
  list_n[[i]] <- c(list1[[i]],list2[[i]])
}

thank you for your help!

pingu87
  • 103
  • 6

0 Answers0