average_spc: Average spectra in list-column by entries in grouping column

View source: R/average-spc.R

average_spcR Documentation

Average spectra in list-column by entries in grouping column

Description

Average spectra in list-column of spectra tibble (spc_tbl) by groups given in group column.

Usage

average_spc(spc_tbl, by = "sample_id", column_in = "spc_rs")

Arguments

spc_tbl

Tibble data frame containing at least the grouping column given in argument by and input spectra given in list-column column_in.

by

Character vector of length 1L or name/symbol that specifies the column by which groups of spectra are averaged. Default is "sample_id".

column_in

Character vector of length 1L or or name/symbol that specifies the list-column that contains the inputs spectra to be averaged. Default is "spc_rs", which are resampled spectra (i.e., resulting after preceding resample_spc() step).

Details

For memory efficiency and subsequent modeling, consider slicing the extra row copies of spc_mean resulting from average_spc() for example by

  • ⁠split(x = spc_tbl, f = spc_tbl$<by>) %>% lapply(., function(x) x x[1, ]) %>% do.call(., rbind)⁠

  • ⁠dplyr::group_by(spc_tbl, <by>) %>% dplyr::slice(1L)⁠

Value

Spectra tibble data frame (class "tbl_df", "tbl", "data.frame") with a new list-column of column name "spc_mean" at the last position, containing mean spectra with identical row replicates within the same by-group.


philipp-baumann/simplerspec documentation built on Oct. 3, 2023, 12:13 p.m.