# Adding elements in the sublists

How can I add the elements in the sublists?
For example, if I have the list which is

 m={{1,3},{2,3},{4,1}}


then, the output that I want is 3+3+1=10. How can I do this?

-
You can use Part to get the elements from the list, then Total to sum them up. – b.gatessucks Oct 30 '12 at 9:44
$3+3+1\neq 10\phantom{}$ – J. M. Oct 30 '12 at 9:57
Plus @@@ (m\[Transpose]) will give you a list of the sums of the various elements of your list. – image_doctor Oct 30 '12 at 10:00
@J.M. which is why this is a tricky question ;-) – chris Oct 30 '12 at 10:25
@J.M. base 7? :^) – Mr.Wizard Oct 30 '12 at 10:56

I thinks the cleanest way is:

Total@m[[All, 2]]


using Esc[[Esc and Esc]]Esc.

If you use it a lot (like me), you can create shortcuts as explained here.

-
You can use these shortcuts if you don't like pressing Esc every time for Part brackets – R. M. Oct 30 '12 at 14:27
Yes, I use it. I put in the post. Tks – Murta Oct 30 '12 at 18:46
@Murta, I asked the Q on [[ ]] but find all the answers a pain. Can you make a palette button or single front-end command? – alancalvitti Nov 13 '15 at 17:29

Following @b.gatessucks

 Total[m[[;; , 2]]]

(* 7 *)


If you want to sum all components (as @image_doctor pointed out too, sorry I missed that)

 Plus @@@ Transpose[m]

(* 7 7 *)

-
Total[m[[All , 2]]] works as well. :) – J. M. Oct 30 '12 at 12:05
Last@Total[{{1, 3}, {2, 3}, {4, 1}}]


or

Total[{{1, 3}, {2, 3}, {4, 1}}]


for both components

-
 {{1, 3}, {2, 3}, {4, 1}} // Query[Total, 2]


7

Unfortunately the current Query and associated Dataset implementation is riddled with workarounds - this is going to tech support >>

{{1, 3}, {2, 3}, {4, 1}} // Query[Total, 2] // Trace // LeafCount


3175

Anyone interested in a timing study?

-

Just For fun.

m = {{1, 3}, {2, 3}, {4, 1}}; Last[Total[m]]

-