Generate a random matrix
stm_random_matrix.Rd
stm_random_matrix()
generates a matrix of random numbers with
specified size and range. Optionally, it allows the user to set the seed
for reproducibility and assign row and column names.
Usage
stm_random_matrix(
min = -4,
max = 9,
nrows = 1,
ncols = nrows,
replace = TRUE,
set_seed = NULL,
row_names = NULL,
col_names = NULL
)
Arguments
- min
Minimum value in the matrix. Default is
-4
.- max
Maximum value in the matrix. Default is
9
.- nrows
Number of rows in the matrix. Default is
1
.- ncols
Number of columns in the matrix. Default is equal to
nrows
.- replace
Logical value indicating whether sampling should be with replacement. Default is
TRUE
.- set_seed
Optional seed value for random number generation.
- row_names
Optional character vector of row names.
- col_names
Optional character vector of column names.
Details
The function generates a matrix of random numbers within the specified
range (min
to max
) and with the specified dimensions
(nrows
and ncols
). If replace
is TRUE
, sampling
is done with replacement. If set_seed
is provided, the random number
generation is reproducible. Additionally, row and column names can be specified.
If the names don't match the matrix dimensions, an error is raised.
See also
stm_random_char
, stm_random_number
, stm_random_vector
, stm_random_matrix
Examples
# note that your values will be different
stm_random_matrix()
#> [,1]
#> [1,] 4
stm_random_matrix(min = 0, max = 1, nrows = 3, ncols = 3)
#> [,1] [,2] [,3]
#> [1,] 0 0 1
#> [2,] 1 0 1
#> [3,] 0 0 0
stm_random_matrix(min = 10, max = 99, nrows = 5, ncols = 4)
#> [,1] [,2] [,3] [,4]
#> [1,] 26 27 53 92
#> [2,] 72 33 32 71
#> [3,] 42 93 61 94
#> [4,] 57 78 29 31
#> [5,] 94 21 13 30