subsample: Sub-sample a spectra collection

Description Usage Arguments Value Examples

View source: R/subsample.R

Description

Pick a subsample form a spectra collection

Usage

1
2
3
4
subsample(x, ...)

## S3 method for class '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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library(tidySpectR)
library(dplyr)

# Randomly sample
subsample(fa_nmr, size = 3)

# Sample one spectra for each labels
subsample(fa_nmr, size= 2, balance_labels = TRUE)

# Subsample specific IDs
subsample(fa_nmr, ids = c("20199305928", "20199306281", "20199504645"))

# Sample alll spectra of specific labels
organic <- fa_nmr$labels %>% 
           filter(label == 'organic') %>%
           pull(id)
subsample(fa_nmr, ids = organic)

# Chain subsamplings to randomly select a spectra with a specific label
subsample(fa_nmr, ids = organic) %>%
  subsample(size=1)

CVUA-RRW/tidySpectR documentation built on April 13, 2021, 11:41 a.m.