AverageByIndex: Bin average from index positions

View source: R/bin-averaging.R

AverageByIndexR Documentation

Bin average from index positions

Description

Calculate bin averages defined by vector index positions.

Usage

AverageByIndex(x, ind, na.rm = TRUE)

Arguments

x

numeric vector for which to compute bin averages according to the indices given in ind.

ind

numeric vector of index positions specifying the binning windows to average over, see details.

na.rm

a logical value indicating whether ‘NA’ values should be stripped before the computation proceeds. Defaults to TRUE.

Details

Averaging bins are defined consecutively from the first index position to the index position one before the next index, i.e., closed on the left and open on the right (the right end of the first bin does not overlap with the left end of the second bin, and so on).

But note that the final bin is treated separately: if the last index coincides with the last data point of x, this point _is_ included in the last bin average, else the bin is treated analogously to the other bins (see examples).

Value

a numeric vector of length length(ind) - 1 with the mean values of each bin from the break points defined by ind.

Author(s)

Thomas Münch

Examples

x <- rnorm(20)

# final bin includes final data point:
AverageByIndex(x, ind = c(1, 7, 13, 17, 20))
# final index is not final data point:
AverageByIndex(x, ind = c(1, 7, 13, 17))

EarthSystemDiagnostics/prxytools documentation built on Jan. 15, 2024, 9:33 p.m.