apply_col {rtrend} | R Documentation |
apply_col
Description
-
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, |
by |
integer vector, with the dim of |
scale |
in the same length of |
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.
Note
This function also suits for big.matrix object.
Examples
mat <- matrix(rnorm(4 * 6), 4, 6)
mat_bycol <- apply_col(mat, c(1, 1, 2, 2), colMeans)
mat_byrow <- apply_row(mat, c(1, 1, 2, 2, 3, 3), rowMeans)
[Package rtrend version 0.1.5 Index]