Hi Paolo,
Some answers to your question included the idiom (&.|:). This idiom is
very useful when working with tables (matrices). Why? Because, given the
design of J, often operations in terms of rows, as opposed to columns, are
easier to write and (&.|:) allows to port quickly a solution for rows to
one for columns.
Allow me to unbox your example data to simplify the display (without
loosing generality). Thus,
( Y=. i.3 3 )
0 1 2
3 4 5
6 7 8
J=. 2
X=. 0 0 0
J ({. , X , }.)&.|: Y
0 1 0 2
3 4 0 5
6 7 0 8
Suppose that now one would like to replace the column 1 of the new table
with (1 2 3). That is, for,
( Y =. J ({. , X , }.)&.|: Y )
0 1 0 2
3 4 0 5
6 7 0 8
J=.1
X=. 1 2 3
How, can one apply this method to accomplish this task? You might want to
try it on your own before looking at a solution shown below after several
blank lines...
X J}&.|: Y
0 1 0 2
3 2 0 5
6 3 0 8
See, http://www.jsoftware.com/pipermail/general/1998-December/000491.html.
You might also like to search for the exact phrase "&.|:" in the forum
archives and you would find plenty of other uses.
I hope this helps.
On Mon, Jul 20, 2015 at 8:11 AM, Strale <[email protected]> wrote:
> Hello
>
> I am trying to combine Tables togethers
>
> for example I would like to insert column before the column 2 of the table
>
> [table =. 3 3 $ <"0 i.9
>
> ┌─┬─┬─┐
>
> │0│1│2│
>
> ├─┼─┼─┤
>
> │3│4│5│
>
> ├─┼─┼─┤
>
> │6│7│8│
>
> └─┴─┴─┘
>
>
> [column =. 3 1$ (<,'0')
>
> ┌─┐
>
> │0│
>
> ├─┤
>
> │0│
>
> ├─┤
>
> │0│
>
> └─┘
>
>
>
> the solution I have found at the moment is the following:
>
>
> [tab2 =. 2|."1 table
>
> ┌─┬─┬─┐
>
> │2│0│1│
>
> ├─┼─┼─┤
>
> │5│3│4│
>
> ├─┼─┼─┤
>
> │8│6│7│
>
> └─┴─┴─┘
>
>
> [tab3 =. column ,"1 1 tab2
>
> ┌─┬─┬─┬─┐
>
> │0│2│0│1│
>
> ├─┼─┼─┼─┤
>
> │0│5│3│4│
>
> ├─┼─┼─┼─┤
>
> │0│8│6│7│
>
> └─┴─┴─┴─┘
>
>
> Result:
>
> 2|."1 tab3
>
> ┌─┬─┬─┬─┐
>
> │0│1│0│2│
>
> ├─┼─┼─┼─┤
>
> │3│4│0│5│
>
> ├─┼─┼─┼─┤
>
> │6│7│0│8│
>
> └─┴─┴─┴─┘
>
>
> Can you suggest me a better solution ?
>
> Thanks
>
> Paolo
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm