Hi Ged,
You might get a better response on the ML than here, but...
You could mod this for your needs. It expects the rows to be
sub-blocks, and it doesn't remove the column you're grouping by, but
it's a general solution. I think this was something I did early in my
REBOLing, so it could probably be greatly improved as well.
group-by: func [ ; See SPLIT
{Returns a block of blocks+sub-blocks with items partitioned by
matching index elements in each sub-block.}
block [any-block!] "A block of series values"
index [integer!] "Index of sub-series value to compare, for grouping."
/part "Compare part of the series, rather than a single value."
range [number!]
/local result val
][
result: copy []
either part [
; First, build up a list of keys, with empty blocks to go with each.
foreach item block [
val: copy/part at item index range
if not find/only/skip result :val 2 [repend result [:val copy []]]
]
; Find the correct place (key) to put an item, and add it there.
foreach item block [
val: copy/part at item index range
append/only select/only result :val item
]
][
; First, build up a list of keys, with empty blocks to go with each.
foreach item block [
val: item/:index
if not find/skip result :val 2 [repend result [:val copy []]]
]
; Find the correct place (key) to put an item, and add it there.
foreach item block [
val: item/:index
append/only select result val item
]
]
result
]
group-by [[a 1 2] [b 2 3] [a 2 4] [c 2 3] [b 1 5]] 1
group-by [[a 1 2] [b 2 3] [a 2 4] [c 2 3] [b 1 5] [c 2 4]] 2
group-by [[a 1 2] [b 2 3] [a 2 4] [c 2 3] [b 1 5] [c 2 4]] 3
group-by/part [[a 1 2] [b 2 3] [a 2 4] [c 2 3] [b 1 5] [c 2 4]] 1 2
group-by/part ["ABC" "AAC" "ABD"] 1 2
--Gregg