0

I am gonna add each element of one list to another in parallel (a.k.a, where element of list_1 are added to element of list_2 in parallel). I used lapply for this but could not get right one. I bet there is must be easy way to do this.

this is my reproducible example:

 list_1 <- list('a'=c(1,1,1), 'b'=c(1,1,1,1))
 list_2 <- list('a_'=c(1,0,0), 'b_'=c(1,1,0,0))

my desired output(just manually sketch my expected output like this):

output <- list('a'= c(2,1,1), 'b'=c(2,2,1,1))

How can I get this result? please help. Thanks a lot

1 Answers1

4

Here is how to do it,

mapply('+', list_1, list_2)
#$a
#[1] 2 1 1

#$b
#[1] 2 2 1 1
Sotos
  • 51,121
  • 6
  • 32
  • 66