Or simply working directly with the table,
a conjunction can be defined that will generate
a verb on the fly for each set of index/values.

   ]DAT=: (<'McGuire')(0 4;2 4)}(<'Tom')(1 2;2 2)}":&.>i.4 5
+--+--+---+--+-------+
|0 |1 |2  |3 |McGuire|
+--+--+---+--+-------+
|5 |6 |Tom|8 |9      |
+--+--+---+--+-------+
|10|11|Tom|13|McGuire|
+--+--+---+--+-------+
|15|16|17 |18|19     |
+--+--+---+--+-------+
   
   Test=: 2 : 'm ="0 1 n {"0 1/ ]'

   ('Tom';'McGuire') Test 2 4
(<;._1 ' Tom McGuire') (="0 1) 2 4 {"0 1/ ]

   ('Tom';'McGuire') Test 2 4 DAT
0 1 1 0
1 0 1 0

   DAT #~ +./ ('Tom';'McGuire') Test 2 4 DAT
+--+--+---+--+-------+
|0 |1 |2  |3 |McGuire|
+--+--+---+--+-------+
|5 |6 |Tom|8 |9      |
+--+--+---+--+-------+
|10|11|Tom|13|McGuire|
+--+--+---+--+-------+
   DAT #~ *./ ('Tom';'McGuire') Test 2 4 DAT
+--+--+---+--+-------+
|10|11|Tom|13|McGuire|
+--+--+---+--+-------+


--- Roger Hui <[EMAIL PROTECTED]> wrote:

> See http://www.jsoftware.com/jwiki/Essays/Inverted_Table
> If your data is appropriately organized as an inverted table
> you should be able to do
> 
> (<(2 4{dat) tmemberof ,:&.>'Tom';'McGuire') #&.> dat
> 
> Setting up the search target requires some care.
> You need to ensure that each opened item is a 
> matrix (thus the ,:&.>) and that each opened item 
> has the correct number of character columns 
> (not shown above).
> 
> Once you have done this, you can define a dyad
> whose left argument is the DB ("dat") and whose
> right argument are the target values, with a:
> indicating "don't care".  e.g.
> 
> where=: dyad define
>  x #&.>~ <x tmemberof&((a: I.@:~: y)&{) y
> )
> 
> dat where a:,a:,(<,:'Tom   '),a:,(<,:'McGuire    '),a:, ...
> 
> 
> 
> ----- Original Message -----
> From: The World <[EMAIL PROTECTED]>
> Date: Tuesday, March 4, 2008 9:04
> Subject: [Jgeneral] best practice for argument handling
> To: General forum <[email protected]>
> 
> > I want to pull all rows from a boxed table that I've created in 
> > J, based 
> > on specific values in certain columns. This is similar
> > to using WHERE  <colvalue> = <value> to formulate SQL 
> > queries. In J I 
> > can do this by hand using standard J operators. Now I would like 
> > to pull 
> > it into a dyadic verb but I'm having trouble deciding the most 
> > common 
> > way to formulate the arguments. The y value is easy it will the 
> > variable 
> > that holds the table data (in this case I call it "dat"). But 
> > now having 
> > used my y argument I now need to stuff into the x argument the 
> > column 
> > numbers I want to base selection from and the strings that will 
> > be used 
> > to test for equality. Just so you get a feeling for what I'm 
> > trying to 
> > do the by hand formulation is as follows:
> > 
> > ((2 }"1 dat) = <, 'Tom') *. (4}"1 dat) = <, 'McGuie'
> > 
> > The above giving me a boolean array where  the ones 
> > represent the  rows 
> > where  col 2 = Tom and Col4 =McGuire. Then I can just apply 
> > the answer 
> > with copy (#) to give me a new array with just those rows that 
> > are 
> > equal  in col2 and col4.
> > 
> > So is there a better way to organize this? Do you make the table 
> > "dat" 
> > global freeing up the y argument? I can certainly brute force 
> > this but 
> > I'm hoping for a more elegant solution that will be applicable 
> > to future 
> > problem spaces.
> > 
> > Tom McGuire
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 



      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to