Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sample

Random Samples and Permutations Take a sample of the specified size from the elements of x with or without replacement.


Description

Random Samples and Permutations Take a sample of the specified size from the elements of x with or without replacement.

isample returns an vector of indices, sample returns the corresponding hyperSpec object.

Usage

## S4 method for signature 'hyperSpec'
sample(x, size, replace = FALSE, prob = NULL)

isample(x, size = nrow(x), replace = FALSE, prob = NULL)

## S4 method for signature 'data.frame'
sample(x, size, replace = FALSE, prob = NULL, drop = FALSE)

## S4 method for signature 'matrix'
sample(x, size, replace = FALSE, prob = NULL, drop = FALSE)

Arguments

x

The hyperSpec object, data.frame or matrix to sample fromto sample from

size

positive integer giving the number of spectra (rows) to choose.

replace

Should sampling be with replacement?

prob

A vector of probability weights for obtaining the elements of the vector being sampled.

drop

see drop: by default, do not drop dimensions of the result

Value

a hyperSpec object, data.frame or matrix with size rows for sample, and an integer vector for isample that is suitable for indexing (into the spectra) of x.

vector with indices suitable for row-indexing x

Author(s)

C. Beleites

See Also

Examples

sample (flu, 3)

plot (flu, col = "darkgray")
plot (sample (flu, 3), col = "red", add = TRUE)

plot (flu, col = "darkgray")
plot (sample (flu, 3, replace = TRUE), col = "#0000FF80", add = TRUE,
      lines.args = list (lwd = 2));

isample (flu, 3)
isample (flu, 3, replace = TRUE)
isample (flu, 8, replace = TRUE)
sample (cars, 2)
sample (matrix (1:24, 6), 2)

hyperSpec

Work with Hyperspectral Data, i.e. Spectra + Meta Information (Spatial, Time, Concentration, ...)

v0.100.0
GPL (>= 3)
Authors
Claudia Beleites [aut, cre, dtc] (<https://orcid.org/0000-0003-1626-154X>), Valter Sergo [aut], Alois Bonifacio [ctb, dtc], Marcel Dahms [ctb], Björn Egert [ctb], Simon Fuller [ctb], Vilmantas Gegzna [ctb], Rustam Guliev [ctb], Bryan A. Hanson [ctb], Michael Hermes [ctb], Martin Kammer [dtc], Roman Kiselev [ctb], Sebastian Mellor [ctb]
Initial release
2021-09-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.