On Mon, Sep 7, 2009 at 11:56 PM, PackRat<[email protected]> wrote:
> I can't figure out how to make # apply to all the values in the row at
> once

You have to box the data again before you reassemble it.  Some other
messages show tricky ways to do this automatically with the under conj
(or even level, yuck), but it's probably easier to do it by hand.
Firstly, as you've shown, this works:

11:03 < b_jonas> ):: t1=: '2009-09-04';'2009-09-03';'2009-09-02';'2009-09-01'
11:03 < jeval> b_jonas: |ok
11:03 < b_jonas> ):: mm=: 1 1 1 1 0 1 1 0 1 1
11:03 < jeval> b_jonas: |ok
11:03 < b_jonas> ):: mm # > 0{t1
11:03 < jeval> b_jonas: 20090904

so you box the result again this way:

11:03 < b_jonas> ):: < mm # > 0{t1
11:03 < jeval> b_jonas: +--------+
11:03 < jeval> b_jonas: |20090904|
11:03 < jeval> b_jonas: +--------+

But to apply this to each cell, you have to define a single verb that
takes a boxed cell and produces another boxed cell:

11:07 < b_jonas> ):: ([: < mm # >) 0{t1
11:07 < jeval> b_jonas: +--------+
11:07 < jeval> b_jonas: |20090904|
11:07 < jeval> b_jonas: +--------+

and then you can apply this verb to the whole boxed list:

11:08 < b_jonas> ):: ([: < mm # >)"0 t1
11:08 < jeval> b_jonas: +--------+--------+--------+--------+
11:08 < jeval> b_jonas: |20090904|20090903|20090902|20090901|
11:08 < jeval> b_jonas: +--------+--------+--------+--------+

Now if you have multiple rows and different masks for each, that's
more complicated.  You would have to generalize the verb so it takes
the mask as an argument as well instead of working with a fixed mask,
like (note that we have to each with rank _ 0 to apply a single mask
to each atom on the right)

11:10 < b_jonas> ):: mm ([: < [ # >@:])"_ 0 t1
11:10 < jeval> b_jonas: +--------+--------+--------+--------+
11:10 < jeval> b_jonas: |20090904|20090903|20090902|20090901|
11:10 < jeval> b_jonas: +--------+--------+--------+--------+

This, however, doesn't work yet because the mask is taken as an open
list so there's no way to pass multiple lists of different sizes.
Thus, we have to take a boxed list:

11:18 < b_jonas> ):: (< mm) ([: < >@:[ # >@:])"0 t1
11:18 < jeval> b_jonas: +--------+--------+--------+--------+
11:18 < jeval> b_jonas: |20090904|20090903|20090902|20090901|
11:18 < jeval> b_jonas: +--------+--------+--------+--------+
and now this verb can be applied to multiple rows with a mask for each:

11:12 < b_jonas> ):: ]t=: t1 ,: '9345.36';'9282.03';'9306.21';'9492.32'
11:12 < jeval> b_jonas: +----------+----------+----------+----------+
11:12 < jeval> b_jonas: |2009-09-04|2009-09-03|2009-09-02|2009-09-01|
11:12 < jeval> b_jonas: +----------+----------+----------+----------+
11:12 < jeval> b_jonas: |9345.36   |9282.03   |9306.21   |9492.32   |
11:12 < jeval> b_jonas: +----------+----------+----------+----------+
11:19 < b_jonas> ):: ]m=: mm;1 1 1 1 0 1 1
11:19 < jeval> b_jonas: +-------------------+-------------+
11:19 < jeval> b_jonas: |1 1 1 1 0 1 1 0 1 1|1 1 1 1 0 1 1|
11:19 < jeval> b_jonas: +-------------------+-------------+
11:19 < b_jonas> ):: m ([: < >@:[ # >@:])"0"0 1 t
11:19 < jeval> b_jonas: +--------+--------+--------+--------+
11:19 < jeval> b_jonas: |20090904|20090903|20090902|20090901|
11:19 < jeval> b_jonas: +--------+--------+--------+--------+
11:19 < jeval> b_jonas: |934536  |928203  |930621  |949232  |
11:19 < jeval> b_jonas: +--------+--------+--------+--------+

Note that you definitely need two diadic ranks (("0)("0 1)) on the
verb, just any one rank wouldn't suffice because you're matching the
atoms of one list with each element of the matching rows of the other.

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

Reply via email to