| average | R Documentation |
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.
average(x, group_by = NULL, .group_by = deprecated())
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 |
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.
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.
Christian L. Goueguel
data(forageLIBS)
# one mean spectrum per sample: three samples were measured twice
means <- average(forageLIBS[-c(1, 3:14)], Sample)
dim(means)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.