This is at least mildly related to an earlier quesiton I asked @marcosh - Nice data-structure for grouping?
In that thread, I ended up following basically @tcard 's advice ( Nice data-structure for grouping? - #4 by tcard ) but perhaps @mixphix 's library is more to your interest - Nice data-structure for grouping? - #7 by mixphix
I also think it would be worth a glance at @LaurentRDC 's fancy new javelin library: Data.Series ; but it might not work as you need a dataframe-like thing, instead of a series. But maybe, if we ask nicely, @LaurentRDC will add such a feature