d (<@#~ (e.&>/~ ~.@;)) c
+-------+-----------+-----+--+--+--+--+
|9 12 15|10 12 14 16|10 15|11|13|14|17|
+-------+-----------+-----+--+--+--+--+

   |: d (~.@;@] ;"0 (e.&>/~ ~.@;)@] <@# [) c
+-------+-----------+-----+--+--+--+--+
|3      |2          |5    |11|13|7 |17|
+-------+-----------+-----+--+--+--+--+
|9 12 15|10 12 14 16|10 15|11|13|14|17|
+-------+-----------+-----+--+--+--+--+

   |: c ;group d
+-------+-----------+-----+--+--+--+--+
|3      |2          |5    |11|13|7 |17|
+-------+-----------+-----+--+--+--+--+
|9 12 15|10 12 14 16|10 15|11|13|14|17|
+-------+-----------+-----+--+--+--+--+

--- Raul Miller <[EMAIL PROTECTED]> wrote:

> I've often wished for variants on /. -- I'd like its verb to see its
> right argument.  I'd like to be able to group on a variety of
> keys (emulating 2 verb\ ] instead of _2 verb\ ]), etc.
> 
> All these are possible currently, of course, but they
> require a bit more thought and effort (and time).  And,
> once I've got a verb, I wonder if it can be done more
> simply.
> 
> For example, let's say d is some data to be grouped and
> c is a boxed list of categories each data element belongs
> to:
> 
>    c=:[EMAIL PROTECTED]:&.>d=:9+i.9
> 
> I want to group each element in d according to these
> categories, and I want each category to remain associated
> with each group (let's pretend like I'm dealing with a general
> case where you cannot assume anything about which
> members of the potential domain are in d):
> 
>    |:/:~ c >@(~.@;@[ ;&.> ;@[ </. #@>@[ # ]) d
> +-----------+-------+-----+--+--+--+--+
> |2          |3      |5    |7 |11|13|17|
> +-----------+-------+-----+--+--+--+--+
> |10 12 14 16|9 12 15|10 15|14|11|13|17|
> +-----------+-------+-----+--+--+--+--+
> 
> (The sort and transpose are for conceptualization purposes,
> representing some arbitrary later operation I might want to
> perform on the grouped collection.)
> 
> Can anyone think of a more concise way of expressing this
> analogy to /. than
> 
>    group=:1 :'u&>/"1@|:@>@(~.@;@[ ,&<&.> ;@[ </. #@>@[ # ])'
>    c ;group d
> 
> ?
> 
> Thanks,
> 
> -- 
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 



       
____________________________________________________________________________________Need
 a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to