Learn R Programming

spectrolab (version 0.0.18)

subset_by: 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 spectra subset_by(x, by, n_min, n_max, random = TRUE)

Value

spectra

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

Methods (by class)

  • subset_by(spectra): Subset spectra by factor

Author

Jose Eduardo Meireles

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`.

Examples

Run this code
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)

Run the code above in your browser using DataLab