title: Assigning a specific number of values informed by a probability distribution (in R)
body: <p>Hello and thanks in advance for the help!</p>
  
  <p>I am trying to generate a vector with a specific number of values that are assigned according to a probability distribution.  For example, I want a vector of length 31, contained 26 zeroes and 5 ones.  (The total sum of the vector should always be five.)  However, the location of the ones is important.  And to identify which values should be one and which should be zero, I have a vector of probabilities (length 31), which looks like this:</p>
  
  <pre><code>probs&lt;-c(0.01,0.02,0.01,0.02,0.01,0.01,0.01,0.04,0.01,0.01,0.12,0.01,0.02,0.01,
  0.14,0.06,0.01,0.01,0.01,0.01,0.01,0.14,0.01,0.07,0.01,0.01,0.04,0.08,0.01,0.02,0.01)
  </code></pre>
  
  <p>I can select values according to this distribution and get a vector of length 31 using rbinom, but I can't select exactly five values.</p>
  
  <pre><code>Inv=rbinom(length(probs),1,probs)
  Inv
  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks again!</p>