pull_sample: Random sample of spectra

View source: R/mspct.sample.R

pull_sampleR Documentation

Random sample of spectra

Description

A method to extract a random sample of members from a list, a collection of spectra or a spectrum object containing multiple spectra in long form.

Usage

pull_sample(x, size, ...)

## Default S3 method:
pull_sample(x, size, ...)

## S3 method for class 'list'
pull_sample(
  x,
  size = 1,
  replace = FALSE,
  keep.order = TRUE,
  simplify = FALSE,
  ...
)

## S3 method for class 'generic_spct'
pull_sample(
  x,
  size = 1,
  replace = FALSE,
  recursive = FALSE,
  keep.order = TRUE,
  ...
)

## S3 method for class 'generic_mspct'
pull_sample(
  x,
  size = 1,
  replace = FALSE,
  recursive = FALSE,
  keep.order = TRUE,
  simplify = FALSE,
  ...
)

Arguments

x

An R object possibly containing multiple spectra or other components.

size

integer The number of spectra to extract, if available.

...

currently ignored.

replace

logical Sample with or without replacement.

keep.order

logical Return the spectra ordered as in x or in random order.

simplify

logical If size = 1, and x is a collection return the spectrum object instead of a collection with it as only member.

recursive

logical If x is a collection, expand or not member spectra containing multiple spectra in long form into individual members before sampling.

Value

If x is an spectrum object, such as a "filter_spct" object, the returned object is of the same class but in most cases containing fewer spectra in long form than x. If x is a collection of spectrum objecta, such as a "filter_mspct" object, the returned object is of the same class but in most cases containing fewer member spectra than x.

Methods (by class)

  • pull_sample(default): Default for generic function

  • pull_sample(list): Specialization for generic_spct

  • pull_sample(generic_spct): Specialization for generic_spct

  • pull_sample(generic_mspct): Specialization for generic_mspct

See Also

See sample for the method used for the sampling.

Examples

a.list <- as.list(letters)
names(a.list) <- LETTERS
set.seed(12345678)
pull_sample(a.list, size = 8)
pull_sample(a.list, size = 8, keep.order = FALSE)
pull_sample(a.list, size = 8, replace = TRUE)
pull_sample(a.list, size = 8, replace = TRUE, keep.order = FALSE)
pull_sample(a.list, size = 1)
pull_sample(a.list, size = 1, simplify = TRUE)


photobiology documentation built on Oct. 21, 2023, 1:06 a.m.