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