R generate an simple integer matrix with defined number of row and column

13,773
matrix(sample.int(15, size = 9*100, replace = TRUE), nrow = 9, ncol = 100)

or the more concise version

matrix(sample.int(15, 9*100, TRUE), 9, 100)

but if you are really going for minimum number of characters (I would not recommend):

matrix(sample(15,900,T),9)
Share:
13,773
S12000
Author by

S12000

Updated on July 03, 2022

Comments

  • S12000
    S12000 almost 2 years

    How to generate an integer random matrix with value from {1 ... 15} in r with 9 row and 100 column for instance ?

    (My question may be basic but for unknown reasons I can't find a solution)