Now use your idea to extend to a definition.. 

f=: 13 :'<"0 x|."1((1{$y)$0),.x|."1"1 y'

   5 f i.8 8

┌──┬──┬──┬──┬─┬──┬──┬──┬──┐
│1 │2 │3 │4 │0│5 │6 │7 │0 │
├──┼──┼──┼──┼─┼──┼──┼──┼──┤
│9 │10│11│12│0│13│14│15│8 │
├──┼──┼──┼──┼─┼──┼──┼──┼──┤
│17│18│19│20│0│21│22│23│16│
├──┼──┼──┼──┼─┼──┼──┼──┼──┤
│25│26│27│28│0│29│30│31│24│
├──┼──┼──┼──┼─┼──┼──┼──┼──┤
│33│34│35│36│0│37│38│39│32│
├──┼──┼──┼──┼─┼──┼──┼──┼──┤
│41│42│43│44│0│45│46│47│40│
├──┼──┼──┼──┼─┼──┼──┼──┼──┤
│49│50│51│52│0│53│54│55│48│
├──┼──┼──┼──┼─┼──┼──┼──┼──┤
│57│58│59│60│0│61│62│63│56│
└──┴──┴──┴──┴─┴──┴──┴──┴──┘

And look at the tacit definition J uses: 

 

  f

[: <"0 [ |."1 (0 $~ 1 { [: $ ]) ,. |."1"1

   

   

   

   

 

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Linda Alvord
Sent: Monday, July 20, 2015 4:23 PM
To: [email protected]
Subject: Re: [Jprogramming] insert column into tables

 

It doesn't have to be hard!  You are progressingj well. Here's where you are so 
far.  Take pme ste[ at a to,e frm right to left an it will make good sense...

 

 

]T=:(<"0)2|."1(,.0 0 0),.2|."1"1 i.3 3

┌─┬─┬─┬─┐

│0│1│0│2│

├─┼─┼─┼─┤

│3│4│0│5│

├─┼─┼─┼─┤

│6│7│0│8│

└─┴─┴─┴─┘

   

Linda

 

-----Original Message-----

From:  <mailto:[email protected]> 
[email protected] [ 
<mailto:[email protected]> 
mailto:[email protected]] On Behalf Of Kip Murray

Sent: Monday, July 20, 2015 9:18 AM

To:  <mailto:[email protected]> [email protected]

Subject: Re: [Jprogramming] insert column into tables

 

Following up on Raul's "use transpose" idea:

 

   tbl

0 1 2

3 4 5

6 7 8

   insertcol =: 1 : '({. , m , }.)&.|:'

   2 (0 0 0 insertcol) tbl

0 1 0 2

3 4 0 5

6 7 0 8

 

--Kip Murray

 

On Monday, July 20, 2015, Raul Miller < <mailto:[email protected]> 
[email protected]> wrote:

 

> The classic "insertion" method for J is to use {. for the part before 

> the insertion and }. for the part after the insertion.

> 

> An example of this might be:

>    table =: 3 3 $  <"0 i.9

>    column =: 3 1$ (<,'0')

>    column ((2{."1]),.[,.2}."1]) table

> 

> But it also might be simpler to use transpose:

>    column ((2{.]), [, 2}.])&.|: table

> 

> Another alternative uses # with a complex left argument (or #inv with 

> a zero in the left argument). I've seen some examples of that here, so 

> I won't post more of them.

> 

> Another alternative, though, involves tacking the column onto the end 

> of the table and then reordering:

>    (<_2}.i._4) C."1 table,.column

> 

> (There are other ways of accomplishing the reordering, but I think 

> this is the clearest. The i._4 cycle rotates things in the direction 

> we want, and the _2 drops the two smallest indexes from the 

> permutation, and the net result is that the column moves to column 

> index 2 of the result.)

> 

> I expect that there could be other ways also, but this is all that 

> occur to me at the moment.

> 

> Thanks,

> 

> --

> Raul

> 

> 

> On Mon, Jul 20, 2015 at 8:11 AM, Strale <[email protected] 

> <javascript:;>>

> 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> http://www.jsoftware.com/forums.htm

> ----------------------------------------------------------------------

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

 

 

 

--

Sent from Gmail Mobile

----------------------------------------------------------------------

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

 

----------------------------------------------------------------------

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

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

Reply via email to