Subset-wise apply functions to aggregate rows or columns of matrix-like objects