title: Exchanging elements (crossover) between two vectors
body: <p>Assume I have:</p>
  
  <p><code>chromosome_1 &lt;- c('0010000001010000')</code></p>
  
  <p><code>chromosome_2 &lt;- c('0100000001001010')</code></p>
  
  <p>How can I implement <strong><em>step 3-5</em></strong> ? </p>
  
  <ol>
  <li>Evaluate
  
  <ul>
  <li>NC1 = no. of 1's in <code>chromosome_1</code></li>
  <li>NC2 = no. of 1's in <code>chromosome_2</code></li>
  <li>M = <code>min(NC1, NC2)</code></li>
  </ul></li>
  <li>Generate a random integer <code>NC</code> from <code>range(1, M)</code></li>
  <li><p>Randomly select <code>NC</code> gene positions among the genes
  with allele “1” from <code>chromosome_1</code> and form a set <code>s1</code> of indices of
  such selected positions.</p>
  
  <p>Randomly select <code>NC</code> gene positions among the genes
  with allele “1” from <code>chromosome_2</code> and form a set <code>s2</code> of indices of
  such selected positions.</p></li>
  <li><p><code>s = union(s1, s2)</code> <strong>Assume</strong> <code>s = 2, 3, 10, 15</code></p></li>
  <li><p>for each index <code>i</code> in <code>s</code></p>
  
  <p>Exchange the alleles of chromosomes <code>chromosome_1</code> and <code>chromosome_2</code> at
  gene position <code>i</code>.</p></li>
  </ol>
  
  <p>The following illustrates the outcome:</p>
  
  <p><a href="https://i.stack.imgur.com/E53Uz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E53Uz.jpg" alt="enter image description here"></a></p>
  
  <p>I would really really appreciate any help!</p>