this will work if y is sorted (easily fixed if not) and indexed continuously
(left column) from 1 to #y
(x ,. ]) (1 -~ {: |: x) { {: |: y
otherwise, we need to make an indexlookup verb (just i.~) as the left argument
for { .
(x ,. ]) (({: |: x) i.~ ({. |: y)) { {: |: y
rajoin =: 4 : '(x ,. ]) (({: |: x) i.~ ({. |: y)) { {: |: y'
----- Original Message ----
From: Yuvaraj Athur Raghuvir <[EMAIL PROTECTED]>
To: Programming forum <[email protected]>
Sent: Sunday, October 22, 2006 7:56:00 PM
Subject: Re: [Jprogramming] Re: Using position-match array to generate result -
eliminate the for loop
x =. 3 2 $ 1 1 2 1 3 2
]x
1 1
2 1
3 2
]y =. 3 2 $ 1 1 2 2 3 3
1 1
2 2
3 3
x rajoin y would mean (in my case)
1 1 1 [first row of x joined with first row of y -match of x(0,1) & y(0,0) ]
2 1 1 [second row of x joined with first row of y -match of x(1,1) & y(0,0) ]
3 2 2 [third row of x joined with second row of y -match of x(2,1) & y(1,0)]
I did not understand what you ment by row headers versus column
headers. I think what I have done above is the join as in db tables.
On 10/23/06, Pascal Jasmin <[EMAIL PROTECTED]> wrote:
> is the result you are looking for:
>
> 1 1 1
> 2 1 2
> 3 2 3
>
> instead?
>
> SQL would generally use a column name to join 2 tables. In your case there
> are matching row headers, and so the above would be as SQL-like of a merge
> ... and could handle one array being out of order from the 2nd.
>
> Perhaps if the result below is what you want, perhaps you can describe the
> logical basis for your merge method.
>
> ----- Original Message ----
> From: Yuvaraj Athur Raghuvir <[EMAIL PROTECTED]>
>
> > x =. 3 2 $ 1 1 2 1 3 2
> > y =. 3 2 $ 1 1 2 2 3 3
> > ]r=. x rajoin y
> > 1 1 1
> > 2 1 1
> > 3 2 2
>
>
>
>
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm