Guides/Language FAQ/Row Sum

From J Wiki
Jump to navigation Jump to search

How do I get the row sum of a table?

      ]t=. ?.2 3$5
4 1 3
1 0 3
   +/t    NB. this is column sum
5 1 6

How do I get the row sum of a table?

Use Rank adverb

   +/"1 t
8 4

   +/ rows t
8 4

   +/ items t
8 4

Explanation

+/'s verb rank is _, which means + is inserted in between items (the highest rank cells). You need a verb with rank 1, which means + is inserted between atoms for each line.


Contributed by Oleg Kobchenko