subset_by: Subset spectra by factor

View source: R/transform_spectra.R

subset_byR Documentation

Subset spectra by factor

Description

subset_by subsets spectra by a factor 'by' ensuring that it appears at most 'n_max' times **and** at least 'n_min' times in the dataset.

Usage

subset_by(x, by, n_min, n_max, random = TRUE)

## S3 method for class 'spectra'
subset_by(x, by, n_min, n_max, random = TRUE)

Arguments

x

spectra object

by

vector coercible to factor and of same length as nrow(x)

n_min

int. only keep spectra with at least (inclusive) 'n_min' number of samples per unique 'by'.

n_max

int. keep at most (incl) this number of spectra per unique 'by'

random

boolean. Sample randomly or keep first n_max? Defaults to TRUE

Details

Note that subset_by forces you to provide both a minimum and a maximum number of spectra to be kept for each unique value of ‘by'. In case you’re interested in subsetting only based on 'n_min', set 'n_max' to 'Inf'.

Value

spectra

Methods (by class)

  • subset_by(spectra): Subset spectra by factor

Author(s)

Jose Eduardo Meireles

Examples

library(spectrolab)
spec = as_spectra(spec_matrix_example, name_idx = 1)

# remove spec of species with less than 4 samples
spec = subset_by(spec, by = names(spec), n_min = 4, n_max = Inf)

annakat/spectrolab documentation built on Oct. 14, 2023, 1:16 a.m.