title: Linear programming exercise with constraints in R
body: <p>I'm looking for a library or any other solution for the problem like below.</p>
  
  <p>I have a matrix that I need to fill, possibly randomly, with a fixed number of 1s. Additionally each row and each column have a max value defined that cannot be exceeded (so for example there can be max five 1s in row A and six 1s in column A).</p>
  
  <p>Is there an easy, automatic way to do it in R? I'd need a solution for bigger matrices, for example 50x50.</p>
  
  <p><a href="https://i.stack.imgur.com/15sUE.jpg" rel="nofollow noreferrer">example</a></p>
  
  <p>Thanks</p>