I am very sorry to annoy you with my problem.
I wrote a program using examples in the Programming forum. Maybe it
is not smart and not efficient.
arraysubtotal=: 4 : 0
NB. x: specified intervals
NB. y: 1st column: grouping variable
NB. 2nd- : changing to subtotals
'n1 n2'=:$y
classnum=.x Idotr (<(i.n1);0){y
out=.>+/ each (=classnum) (<@#) (<(i.n1);1){y
m=.$out
out=.(m,1)$out
ic=.1
for. i=.i.<:<:n2
do. u=.>+/ each (=classnum) (<@#) (<(i.n1);ic=.>:ic){y
u=.(m,1)$u
out=.out(,"1)u
end.
out
)
array=:|:(u/:u=:(?.10$0)),(?.5 10$10)
array
0.00152749 6 6 1 5 1
0.0784184 5 8 6 7 4
0.236057 9 3 0 8 3
0.372207 2 8 4 8 9
0.424654 4 1 4 2 7
0.443886 9 2 1 1 2
0.544194 0 8 3 9 4
0.629304 7 0 3 7 3
0.817135 0 0 6 9 7
0.970635 4 2 6 9 5
0 0.5 arraysubtotal array
35 28 16 31 26
11 10 18 34 19
0 0.2 0.6 0.8 arraysubtotal array
11 14 7 12 5
24 22 12 28 25
7 0 3 7 3
4 2 12 18 12
NB. The first column is just used as grouping variable like time and
ordered.
This is just an example for illustration. I am worried that this
code does not work well for very large matrix because (=classnum)
generates very large sparse matrix.
Best regards.
Toshinari Kamakura
On 2007/04/27, at 21:56, Dan Bron wrote:
Toshinari Kamakura asked:
is it possible to make subtotals of other
variables based on the X variable?
interval X: x0 x1 x2 xn
Y:(length m1)
Z:(matrix m1*m2)
We would like to make subtotal matrix based on the Y
variables with interval X.
Could you elaborate on your question a bit?
If you mean Z is just a set of vectors like Y, then try sbt"1 Z .
But if Z is the desired output, then I'm confused. How is Z
related to X and Y? If x1 x1 ... xn means that there are N numbers
in X, then did you mean that Z is a m1 ? N matrix? If so, what
is the definition of each element?
Perhaps you could supply an example input and output; that would be
the most helpful.
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm