table-, tapply-, and split-like functionality for matrix and