mardi 31 janvier 2017

Generating binary matrix with fixed number of 1's

How can I generate a binary matrix that has the following behavior? I have came across this solution but it lacks the random positioning of the binary values.

## all rows contain four 1's at random column

       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1    1    1    0    0    0    0    0    1     0
 [2,]    0    0    0    1    1    1    0    0    0     1
 [3,]    0    0    0    1    1    0    0    1    1     0
 [4,]    0    1    1    0    0    0    1    0    0     1
 [5,]    0    1    0    1    0    1    0    1    0     0




Aucun commentaire:

Enregistrer un commentaire