Skip to content
Prev 278781 / 398502 Next

fill binary matrices with random 1s

On Nov 29, 2011, at 7:32 AM, Grant McDonald wrote:

            
Ewww. That looks painful. Consider this as an alternative to create a  
single such "random matrix":

rmat <- matrix(rbinom(100, 1, prob=0.1), 10,10)

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