This is something that should be simple, but the documentation and other questions don't seem to deal with it. I can think of mechanically doing it through a loop, but I know there must be a better way.
In this example, I have three lists (although the actual operation will involve several sets of 20-30 each, and they're much longer):
list1={1,5,5,5,5,6};
list2={2,1,2,2,2,2};
list3={3,3,3,3,3,3};
What I need to do is add them together - as in all the first positions of the three lists being added together, all the second positions, and all the third positions, so that I just have say:
list4={6,9,10,10,10,11};
The actual order of the list is important (I'm using it to store data). Thanks in advance.
Answer
There is another approach (much better) - Total :
Total[{list1, list2, list3}]
{6, 9, 10, 10, 10, 11}
or Apply the function Plus :
Plus @@ {list1, list2, list3}
or
MapThread[ Plus, {list1, list2, list3}]
Comments
Post a Comment