average: Fast Average for Large Spectral Dataset

View source: R/average.R

averageR Documentation

Fast Average for Large Spectral Dataset

Description

This function efficiently averages the samples spectra in a large dataset. It provides flexibility by computing either the overall mean across all spectra or group-wise means based on the values of a specified grouping column.

Usage

average(x, group_by = NULL, .group_by = deprecated())

Arguments

x

A data frame or tibble.

group_by

The column to group the data by (optional), given either unquoted or as a string. If not provided, the average of the overall data will be computed.

.group_by

[Deprecated] Use group_by.

Details

The function leverages the power of Rcpp to perform the mean calculations in C++. The underlying C++ implementation has a time complexity of O(n x m), where n is the number of rows and m is the number of columns in the data. Missing values are ignored in the computation of each mean.

Value

  • If group_by = NULL, a one-row tibble containing the mean of each column.

  • If group_by is provided, a tibble with one row per group: the first column holds the group labels and the remaining columns hold the group means.

Author(s)

Christian L. Goueguel

Examples

data(forageLIBS)
# one mean spectrum per sample: three samples were measured twice
means <- average(forageLIBS[-c(1, 3:14)], Sample)
dim(means)

specProc documentation built on Nov. 20, 2026, 5:11 p.m.