Take a sample of the specified size from the elements of x with or without replacement.
# S4 method for hyperSpec sample(x, size, replace = FALSE, prob = NULL) isample(x, size = nrow(x), replace = FALSE, prob = NULL) # S4 method for data.frame sample(x, size, replace = FALSE, prob = NULL, drop = FALSE) # S4 method for matrix sample(x, size, replace = FALSE, prob = NULL, drop = FALSE)
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 |
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
C. Beleites
#> hyperSpec object #> 3 spectra #> 3 data columns #> 181 data points / spectrum #> wavelength: lambda/nm [numeric] 405.0 405.5 ... 495 #> data: (3 rows x 3 columns) #> 1. spc: I[fl]/"a.u." [matrix, array181] 167.26667 93.14433 ... 45.25633 #> 2. filename: filename [character] rawdata/flu5.txt rawdata/flu3.txt rawdata/flu1.txt #> 3. c: c / (mg / l) [numeric] 0.25 0.15 0.05isample(flu, 3)#> [1] 6 4 2isample(flu, 3, replace = TRUE)#> [1] 3 2 1isample(flu, 8, replace = TRUE)#> [1] 3 2 5 3 6 5 1 1#> speed dist #> 34 18 76 #> 50 25 85#> [,1] [,2] [,3] [,4] #> [1,] 3 9 15 21 #> [2,] 4 10 16 22