lundi 4 mai 2020

Getting a fixed number of zeroes randomly in a matrix in R

I have a matrix of size 2000x50. For the 50 places in each of the 2000 rows, I want exactly 6 of them to be 1 and the remaining 44 to be 0. This distribution needs to be random across each row. I have tried using the sample, rbinom functions but none of them seem to be helping. It is also possible that I might not be using them correctly. All thoughts and inputs regarding this will be appreciated.

Thank you.




Aucun commentaire:

Enregistrer un commentaire