Does this look right?

ctbl=. 10 0.5 15 25 35 45 0,20 0.2 15 35 0 0 0,30 1 15 0 45 0 0,:40 0.8 15
45 0 45 0

cvtRow=: 3 : 0"1
  cm=. 0 2 1{"1 (2{.y),"(1 0)/2}.y
  (0~:1{"1 cm)#cm,.(2{"1 cm)*idMat #cm
)

idMat=: 3 : '(2$y.)$(>:y.){.1' NB.* idMat: y by y identity mat
cvtMat=: 13 : '>,&.>/cvtRow&.><"1 y'

  cvtMat ctbl
10 15 0.5 0.5 0 0 0 0
10 25 0.5 0 0.5 0 0 0
10 35 0.5 0 0 0.5 0 0
10 45 0.5 0 0 0 0.5 0
20 15 0.2 0.2 0 0 0 0
20 35 0.2 0 0.2 0 0 0
30 15 1 1 0 0 0 0
30 45 1 0 0 1 0 0
40 15 0.8 0.8 0 0 0 0
40 45 0.8 0 0.8 0 0 0
40 45 0.8 0 0 0 0.8 0



On 7/20/07, Alex Rufon <[EMAIL PROTECTED]> wrote:

Hello.

This has stumped me. I just cant get my brains around this one.

I have this table (TABLE A):
TABLE A
material_code   consumption     colorway1       colorway2
colorway3       colorway4       colorwayN
10      0.5     15      25      35      45      0
20      0.2     15      35      0       0       0
30      1       15      0       45      0       0
40      0.8     15      45      0       45      0

And I need to transform into this format (TABLE B):
TABLE B
material_code   color   total   colorway1       colorway2
colorway3       colorway4       colorwayN
10      15      0.5     0.5     0       0       0       0
10      25      0.5     0       0.5     0       0       0
10      35      0.5     0       0       0.5     0       0
10      45      0.5     0       0       0       0.5     0
20      15      0.2     0.2     0       0       0       0
20      35      0.2     0       0.2     0       0       0
30      15      1       1       0       0       0       0
30      45      1       0       0       1       0       0
40      15      0.8     0.8     0       0       0       0
40      45      1.6     0       0.8     0       0.8     0

Please note that the number of colorways may be from 1 to N. Its
arbitrarily sized.

I've also attached a capture of the excel file on the event that this
becomes unreadable.

I would really appreciate if anybody would give my problem a go. Otherwise
... I'll do a brute-force solution. I have an idea on how to do this but its
going to be really ugly with a lot of branching and conditions. Oh well, I'm
going get some sleep (been away for 20 hours).

Thanks in advance to anybody who give this a go. I appreciate any help.

Thanks again.

r/Alex

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to