samedi 20 août 2022

Fill a NA matrix using apply functions

I want to fill an empty matrix using the apply function. For example, my purpose is to simplify the following code

tmp <- matrix(NA, 10, 10)
tmp[, 1] <- sample(1:500, 10)
tmp[, 2] <- sample(1:500, 10)
...
tmp[, 10] <- sample(1:500, 10)

Is it possible to make the code above just one line using the apply function? If it is not, recommendation of any kind of simpler code may be helpful for me:)




Aucun commentaire:

Enregistrer un commentaire