title: R (Stratified) Random Sampling for Defined Cases
body: <p>I have a <strong>data frame</strong>:</p>
  
  <pre><code>DF &lt;- data.frame(Value = c("AB", "BC", "CD", "DE", "EF", "FG", "GH", "HI", "IJ", "JK", "KL", "LM"),
                   ID    = c(1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1))
  </code></pre>
  
  <p>My question: I would like to create a <strong>new column</strong> that includes a (binary) <strong>random number</strong> ('<code>0</code>' or '<code>1</code>') <strong>for cases</strong> <code>'ID' == 1</code> with a <strong>fixed proportion</strong> (or pre-defined prevalence) (e.g., random numbers '<code>0</code>' x 2 and '<code>1</code>' x 4).</p>
  
  <p><strong>EDIT I:</strong>
  For non-case specific purposes, the solution might be:</p>
  
  <pre><code>DF$RANDOM[sample(1:nrow(DF), nrow(DF), FALSE)] &lt;- rep(RANDOM, c(nrow(DF)-4,4))
  </code></pre>
  
  <p>But, I still need the cas-specific assignment AND the aforementioned solution does not explicitly refer to '<code>0</code>' or '<code>1</code>'.</p>
  
  <p>(Note: The variable '<code>value</code>' is not relevant for the question; only an identifier.)</p>
  
  <p>I figured out relevant posts on <a href="https://stackoverflow.com/questions/43726614/stratified-random-sampling-in-r">stratified sampling</a> or <a href="https://stackoverflow.com/questions/8273313/sample-random-rows-in-dataframe">random row selection</a> - but this question is not covered by those (and other) posts.</p>
  
  <p>Thank you VERY much in advance.</p>