apply_col: aggregate by col, return a [ngrp, ncol] matrix
apply_row: aggregate by row, return a [nrow, ngrp] matrix
Usage
apply_col(mat, by, FUN = colMeans2, scale = 1, ...)
apply_row(mat, by, FUN = rowMeans2, scale = 1, ...)
Arguments
mat
matrix, [nrow, ncol]
by
integer vector, with the dim of [ntime]
scale
in the same length of by, or a const value,
value_returned = FUN(x)*scale. This parameter is designed for converting
monthly to yearly, meanwhile multiply days in month.
Currently, same group should have the same scale factor. Otherwise, only the
first is used.
Details
For example, setting the dimension of mat is [ngrid, ntime],
if you want to aggregate by time, apply_row should be used here;
if you want to aggregate by region (grids), apply_col should be used.