Harvey asked:
> For the collective wisdom ...
I'm going to try to rephrase your question. Let me know if I've got it
right.
Your input is a several tables of ID,Value pairs and one canonical list of
all IDs. Your desired output is another ID,Value table, whose first
column is identical to the input list of all IDs, and whose last column
has the corresponding values from the input tables (or zero, if no value
corresponded to the ID).
You prefer a multiline explicit verb solution, because at this point in
your J career, that will be easier for you to read, maintain, and extend.
Assuming the above, then does the following suit?
join =: dyad define
indices =. ({."1 y) i. x
values =. indices { ({:"1 y) , <,'0'
x ,. values
)
tblall join tbl1,tbl2 NB. Append input tables as required
Note that this diverges from your methodology somewhat. Amend } is not
used; this is because you treat tblall as one-column table, and append a
column of zeros, then merge the values from the other tables into that
column. The code above treats tblall as a list of IDs, to ensure all
IDs are represented in the output (i.e. it's the primary key).
I find } is relatively uncommon in J code. While it has elegant uses,
most of the familiar ones from scalar languages are expressed differently
in J (to our benefit).
Also, you merge multiple tables in multiple steps, whereas the above code
treats the aggregation of all ID,Value tables as a single input (the
tables agree in type and shape, and that fact can be leveraged). "Doing
it all at once" is a common pattern in J.
Note that i. will give preference to the values in tbl1 . If you want
to give preference to tbl2 then put it first (i.e. use tbl2,tbl1 ).
I hope this helps,
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm