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.
Value
If
.group_by = NULL
, the function returns a numeric vector containing the mean of each column across all spectra.If
.group_by
is provided, the function returns a data frame with columns corresponding to the unique values in the grouping column. Each cell contains the mean of the corresponding column for that group.
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 × m), where n is the number of rows and m is
the number of columns in the data. This efficient implementation ensures that
the function can handle large datasets without significant performance overhead.
The R wrapper function adds minimal overhead for argument checking and data manipulation, while leveraging the efficient C++ implementation for the core computations. The overall time complexity remains O(n × m).