title: Vector creation and modification based on other vectors
body: <p>I would like to make the code more efficient.</p>
  
  <p>The example creates a vector (called 'new_vector'). The values of this 'new_vector' are changed based on if/else-conditions that refer to the values of three other vectors of the same length. </p>
  
  <p>If the conditions are fulfilled, the corresponding elements of the 'new_vector' are updated using values from one of the other vectors (in the example elements of M_date are written into new_vector).</p>
  
  <p>Here is the example code:</p>
  
  <pre><code>new_vector&lt;-c(9,9,9)
  S_date&lt;-c(1,1,as.Date('2010/08/01'))
  V_date&lt;-c(1,as.Date('2010/09/01'),1)
  M_date&lt;-c(2,as.Date('2010/07/01'),1)
  
  for (i in 1:3) {
      if ( (S_date[i]==1) &amp; (V_date[i]==1 | M_date[i] &lt; V_date[i]) ) {
      new_vector[i]&lt;-M_date[i]
      }
  }
  </code></pre>
  
  <p>The result of the example is:</p>
  
  <pre><code>&gt; new_vector
  [1]     2 14791     9
  </code></pre>
  
  <p>The example is simplified and in reality the vectors are larger and there are additional if/else-conditions.</p>
  
  <p>How can I avoid the loop and use implicit methods for vector operations instead?</p>