Is it important that they be grouped in the order specified by the key? If not, this should do (with C the categories and S the strings):
(⊂[1]C∘.=∪C)/¨⊂S If they must be ordered, then this can do it: (⊂[1]C∘.=U[⍋U←∪C])/¨⊂S In addition, the categories don’t have to be numbers. Note that Dyalog’s (dyadic) key function is equivalent to this, with L being the operator’s left operand: L¨(⊂[1]C∘.=∪C)/¨⊂S Cheers, Louis > On 05 Jul 2017, at 11:43, Elias Mårtenson <loke...@gmail.com> wrote: > > I have a list of strings, and a corresponding set of categorisations: > > strings ← 'foo' 'bar' 'abc' 'def' 'ghi' 'jkl' > categories ← 1 1 0 2 1 0 > > I now need to group these strings according to category. In other words, when > applying operation X, I need the following output: > > categories X strings > ┏→━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ > ┃┏→━━━━━━━━━━┓ ┏→━━━━━━━━━━━━━━━━┓ ┏→━━━━┓┃ > ┃┃"abc" "jkl"┃ ┃"foo" "bar" "hgi"┃ ┃"def"┃┃ > ┃┗∊━━━━━━━━━━┛ ┗∊━━━━━━━━━━━━━━━━┛ ┗∊━━━━┛┃ > ┗∊∊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ > > What is the best way to solve this? >