Generate a random matrix, given a rando function and it's dimensions. By default, this will generate a square matrix.

r_matrix(
  engine,
  row_names = NULL,
  col_names = NULL,
  ...,
  nrow = default_n(row_names),
  ncol = default_n(col_names),
  .seed = NULL
)

Arguments

engine

The rando function that will be used to generate the random numbers

col_names, row_names

names to be assigned to the rows or columns. This is also used in deciding the dimensions of the result.

...

Unused

nrow, ncol

dimensions of the matrix. The default_n() function will provide a default value within context.

.seed

One of the following:

  • NULL (default) will not change the current seed. This is the usual case for generating random numbers.

  • A numeric value. This will be used to set the seed before generating the random numbers. This seed will be stored with the results.

  • TRUE. A random seed value will be generated and set as the seed before the results are generated. Again, this will be stored with the results.

To extract the random seed from a previously generated set of values, use pull_seed()

Value

A matrix with nrow rows and ncol columns an a type as decided by the function passed to engine.

Examples

set_n(5) r_matrix(r_norm)
#> [,1] [,2] [,3] [,4] [,5] #> [1,] -0.4874118 1.4289691 -0.56672262 1.2491076 1.1142686 #> [2,] -0.3984335 -0.4799557 -1.05057219 -0.5487269 0.8469618 #> [3,] -0.6007733 1.2951984 -0.94630671 -1.7103311 0.3908726 #> [4,] -0.2098360 0.1650741 -0.07517996 -0.7009860 1.0536553 #> [5,] 0.4855064 0.3254972 0.18792650 1.8978270 -0.5554843
r_matrix(r_unif,min=1,max=2)
#> [,1] [,2] [,3] [,4] [,5] #> [1,] 1.264539 1.764295 1.048398 1.110759 1.089322 #> [2,] 1.386268 1.961027 1.703607 1.938342 1.785374 #> [3,] 1.619194 1.270585 1.147214 1.846471 1.226957 #> [4,] 1.541678 1.730600 1.769155 1.571144 1.448178 #> [5,] 1.484831 1.134166 1.176350 1.679093 1.161228
r_matrix(r_norm,mean=10,sd=2,ncol=2)
#> [,1] [,2] #> [1,] 8.139429 5.640087 #> [2,] 9.270298 10.841749 #> [3,] 10.307745 9.284943 #> [4,] 10.826310 8.706277 #> [5,] 14.961647 9.899716