averageGroupedStats: Average grouped statistics

View source: R/averageGroupedStats.R

averageGroupedStatsR Documentation

Average grouped statistics

Description

Average grouped statistics with consideration of weights and protection from missing values.

Usage

averageGroupedStats(values, grouping, weights = NULL)

Arguments

values

A numeric vector containing statistics for individual tests.

grouping

A vector or factor of length equal to p.values, specifying the group to which each test is assigned.

Alternatively, an rle object where each run corresponds to a group and specifies the entries of p.values belonging to that group. This assumes that p.values is ordered such that all entries in the same group are adjacent to each other.

weights

A numeric vector of length equal to p.values, containing a positive weight for each test. Alternatively NULL, in which case equal weights are assigned to all tests.

Details

If weights is supplied, a weighted average is computed for each group. If values contains missing values, they are ignored and will not contribute to the average.

Value

A named numeric vector of (weighted) averages, of length equal to the number of unique levels in grouping.

Author(s)

Aaron Lun

See Also

averageParallelStats, for the parallel counterpart.

Examples

grouping <- sample(LETTERS, 20, replace=TRUE)
averageGroupedStats(1:20, grouping)
averageGroupedStats(1:20, grouping, weights=runif(20))


LTLA/metapod documentation built on Jan. 19, 2024, 11:49 p.m.