Create a matrix of given dimension and fill it with random integer values
randomMatrix(dim = c(sample(10, 1), sample(10, 1)), values = seq_len(100))
dim | integer vector of length two containing the number of rows and columns, respectively, that the output matrix shall contain |
---|---|
values | set of values to be used within the matrix |
# By default, the matrix has a random number of rows between 1 and 10 and # a random number of columns between 1 and 10 and random values of 1:100 randomMatrix()#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 82 73 34 47 82 78 22 87 95 67 #> [2,] 70 22 57 92 91 100 30 24 44 41 #> [3,] 23 46 26 98 59 72 73 1 76 36# You may specify the dimensions (here: 5 rows, 3 columns)... randomMatrix(dim = c(5, 3))#> [,1] [,2] [,3] #> [1,] 74 86 17 #> [2,] 67 11 96 #> [3,] 9 49 33 #> [4,] 86 25 37 #> [5,] 8 69 89# ... and the set of values to be used within the matrix randomMatrix(dim = c(5, 3), values = c(0, 0.5, 1, NA))#> [,1] [,2] [,3] #> [1,] NA NA 0 #> [2,] 0.0 0.5 NA #> [3,] NA NA 0 #> [4,] NA 0.0 0 #> [5,] 0.5 0.0 0