View source: R/transform_spectra.R
subset_by | R Documentation |
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.
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)
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 |
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'.
spectra
subset_by(spectra)
: Subset spectra by factor
Jose Eduardo Meireles
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.