avg_columns: Condense a matrix by averaging selected columns

View source: R/bin_funcs.R

avg_columnsR Documentation

Condense a matrix by averaging selected columns

Description

Given a matrix and a list where each element contains a numeric vector of the column indices to average, calculate a condensed matrix.

Usage

avg_columns(mat, dlist = NULL, year = NULL, composite = "8day")

Arguments

mat

Numeric matrix

dlist

List of numeric vectors, where each vector contains the column indices that should be merged (see example). If left blank, mat must be in order and have no gaps (i.e. a day with no data should be a column of all NA), and a year and "composite" are also required so that dlist can be automatically calculated using the 8day or monthly system.

year

Integer, only needed if dlist is NULL

composite

String, length of output composite, 8day or monthly (only needed if dlist is NULL)

Details

This can be used to take a matrix where rows = pixels and columns = days of the year, and average columns over 8day or month intervals to return, for example, a corresponding matrix of row=pixels and columns=weeks (where a "week" is 8days).

Value

Numeric matrix with the same number of rows, and the number of columns equal to the length of dlist

Examples

mat <- matrix(runif(30), nrow=3)
avg_columns(mat, dlist=list(1:5, 6:8))


BIO-RSG/oceancolouR documentation built on April 25, 2024, 12:28 p.m.