Average the replicates in a Spectra object and return a new Spectra object with fewer samples. One should probably not do this until each individual sample has been visualized for quality control, in case it is a potential outlier.

averageReplicates(spectra, uniq)

Arguments

spectra

An object of S3 class Spectra().

uniq

Character. A character vector containing strings representing unique sample identifiers. The sample names will be searched for these strings, and all samples matching a given string will be averaged and put into a new Spectra object. For example, consider the case where samples are named S_1_01, S_1_02, ..., S_2_01, S_2_02, ... where _01 and so forth signifies replicates of a particular sample. With uniq = c("S_1", "S_2") all S_1 replicates will be averaged and all S_2 replicates will be averaged. N.B. the strings will be used as regex pattern and grepped.

Value

An object of S3 class Spectra.

Author

Bryan A. Hanson (DePauw University).

Examples

data(SrE.IR)
averaged <- averageReplicates(SrE.IR, uniq = c("EPO", "OO", "adSrE", "pSrE"))
sumSpectra(SrE.IR)
#> 
#>  Serenoa repens IR quality study 
#> 
#> 	There are 16 spectra in this set.
#> 	The y-axis unit is absorbance.
#> 
#> 	The frequency scale runs from
#> 	399.2123 to 3999.837 wavenumber
#> 	There are 1868 frequency values.
#> 	The frequency resolution is
#> 	1.9286 wavenumber/point.
#> 
#> 
#> 	The spectra are divided into 4 groups: 
#> 
#>   group no.   color symbol alt.sym
#> 1 adSrE  10 #984EA3     15       d
#> 2   EPO   1 #377EB8      2       b
#> 3    OO   1 #4DAF4A      3       c
#> 4  pSrE   4 #E41A1C      1       a
#> 
#> 
#> *** Note: this is an S3 object
#> of class 'Spectra'
sumSpectra(averaged)
#> 
#>  Serenoa repens IR quality study (replicates averaged) 
#> 
#> 	There are 4 spectra in this set.
#> 	The y-axis unit is absorbance.
#> 
#> 	The frequency scale runs from
#> 	399.2123 to 3999.837 wavenumber
#> 	There are 1868 frequency values.
#> 	The frequency resolution is
#> 	1.9286 wavenumber/point.
#> 
#> 
#> 	The spectra are divided into 4 groups: 
#> 
#>   group no.   color symbol alt.sym
#> 1   EPO   1 #377EB8      2       b
#> 2    OO   1 #4DAF4A      3       c
#> 3 adSrE   1 #984EA3     15       d
#> 4  pSrE   1 #E41A1C      1       a
#> 
#> 
#> *** Note: this is an S3 object
#> of class 'Spectra'