Pick a subsample form a spectra collection

subsample(x, ...)

# S3 method for collection
subsample(x, size = 2, balance_labels = FALSE, ids = NULL, ...)

Arguments

x

Acollection object

...

further arguments passed to or from other methods(not currenctly used).

size

Size of the sub-sampling

balance_labels

A boolean, wether to pick spectra equally between labels. If the subsampling size is below the number of labels, not all labels will be chosen from.

ids

A vector of ids to extract, this will override the other parameters.

Value

a subsample of x

Examples

library(tidySpectR) library(dplyr) # Randomly sample subsample(fa_nmr, size = 3)
#> Spectra collection containing 3 entries. #> Number of bins: 2250 #> Limits: -2.123166e-05 8.999979 #> Labels: conventional organic #> #> Processing:
# Sample one spectra for each labels subsample(fa_nmr, size= 2, balance_labels = TRUE)
#> Spectra collection containing 2 entries. #> Number of bins: 2250 #> Limits: -2.123166e-05 8.999979 #> Labels: conventional organic #> #> Processing:
# Subsample specific IDs subsample(fa_nmr, ids = c("20199305928", "20199306281", "20199504645"))
#> Spectra collection containing 3 entries. #> Number of bins: 2250 #> Limits: -2.123166e-05 8.999979 #> Labels: conventional organic #> #> Processing:
# Sample alll spectra of specific labels organic <- fa_nmr$labels %>% filter(label == 'organic') %>% pull(id) subsample(fa_nmr, ids = organic)
#> Spectra collection containing 3 entries. #> Number of bins: 2250 #> Limits: -2.123166e-05 8.999979 #> Labels: conventional organic #> #> Processing:
# Chain subsamplings to randomly select a spectra with a specific label subsample(fa_nmr, ids = organic) %>% subsample(size=1)
#> Spectra collection containing 1 entries. #> Number of bins: 2250 #> Limits: -2.123166e-05 8.999979 #> Labels: conventional organic #> #> Processing: