This function takes n
samples of
size nrow(x)
from the elements of x
.
Two types of sampling are available: sampling with
or without replacement.
Usage
sampleData(x, method = c("none", "permutation", "bootstrap"), n = 1L)
Arguments
- x
numerical matrix, features-by-samples
- method
string, the sampling method to use. Available options are:
Three options are available:
none
a sequence from 1 to
nrow(x)
is returnedpermutation
random sampling without replacement
bootstrap
random sampling with replacement
- n
integer, number of repeated samples to generate
Examples
#set seed for reproducibility
set.seed(seed = 5381L)
#Define row/col size
nr = 20
nc = 10
#Create input matrix
x = matrix(
data = stats::runif(n = nr*nc, min = 0, max = 1000),
nrow = nr,
ncol = nc,
dimnames = list(
paste0("g",seq(nr)),
paste0("S",seq(nc))
)
)
#Take one sample via permutation
#(duplicated elements are not possible)
sampleData(
x = x,
method = 'permutation',
n = 1
)
#> [[1]]
#> [1] 11 9 7 10 19 13 2 4 17 18 12 3 5 8 20 6 15 14 16 1
#>
#Take one sample via bootstrap
#(duplicated elements are possible)
sampleData(
x = x,
method = 'bootstrap',
n = 1
)
#> [[1]]
#> [1] 19 5 20 5 19 5 11 2 5 7 1 13 16 15 8 8 14 17 16 2
#>