Skip to contents

This function takes n samples of size length(i) from the elements of x. Two types of sampling are available: using all elements of x or using the elements of x that are not part of i.

Usage

randomSignatures(x, i, n = 1L, exclude = TRUE)

Arguments

x

a numerical vector or matrix

i

(optional) numerical vector giving the (row) elements in x or character vector matching the (row) names in x

n

integer, number of repeated samples to generate

exclude

logical, whether to exclude i from the possible values

Value

A list of length n where each element is a vector of indices representing the sampled data.

See also

Author

Alessandro Barberis

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))
 )
)

#Set signature
i = rownames(x)[1:10]

#Generate 1 random signatures
#(elements of i are possible)
randomSignatures(
 x = x,
 i = i,
 n = 1,
 exclude = FALSE
)
#> [[1]]
#>  [1] 11  9  7 10 19 13  2  4 17 18
#> 

#Generate 1 random signatures
#(elements of i are excluded)
randomSignatures(
 x = x,
 i = i,
 n = 1,
 exclude = TRUE
)
#> [[1]]
#>  [1] 20 13 15 18 17 16 14 12 19 11
#>