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`.
library(spectrolab)
spec = as_spectra(spec_matrix_example, name_idx = 1)
# remove spec of species with less than 4 samplesspec = subset_by(spec, by = names(spec), n_min = 4, n_max = Inf)