You generate a vector by randomly sampling from 1 to 4 with replacement and then converting the resulting vector into a matrix.
matrix(sample(x = 1:4, size = 35*15, replace = TRUE), nrow = 35, ncol = 15)
This also gives you the option to use other sampling method, like drawing from a binomial distribution.
matrix(rbinom(n = 35*15, 3, 0.5)+1, nrow = 35, ncol = 15)
Although I am not sure when I would use this compared to the sample() solution above.
EDIT: as @jay.sf mentioned, use e.g. set.seed(13)
before randomly sampling numbers in order to be able to reproduce your results.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…