As a first step in analyzing data it is nice to have subtotals by different
parameters.  I guess for example one could get total salaries, costs and
sales totaled for an entire country and subtotaled by region, sex, age of a
sales-force.  Each sale can then be included in an array of 6 columns in
this case.  Each subtotal would be produced with:

mt=:(/:~)@(([:~.{."1 ),.{."1 +//. }."1)

In our case,

3 mt (a: 6-column array)

would produce all sub-totals. But for all levels of sub-totals as well as
the grand total, the following would do:

m=: 4 : 0
 w=. (0,{:$y)$0
 u=.y
 for_t. i.-x+1 do.
  u=. t mt u
  if. t < x do. u=. _ (<a:;t)}u end.
 w=.w,u
 end.
 /:~w
)

on my iPad, i get:
  ts'4 m ?.1000000$,: 4 5#5 100'
time:    4.39185
space: 1.97136e8

But I have not ben lucky wit a one-liner on this, I tried:

    3    (}.@])`(($:<:@[)(],mt)])@.(0<[)a
|stack error
|   3    (}.@])`(($:<:@[)(],mt)])@.(0<[)a

Expecting to substitute mt into this line and get a mean one-liner.

Any hints or suggestion?

Robert Cyr


Sent from my iPad
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to