title: Avoid FOR loop in R programming
body: <p>I have 2 dataframes below,</p>
  <pre><code>col1_x &lt;- c(0123,123,234,4567,77789,4578,45588,669887,7887,5547)
  col2_x &lt;- c('X1','X8','X2','X55','C12','B11','Z1','SS12','D9','F55')
  a    &lt;- c(10,9,8,7,6,5,4,3,2,1)
  DF1 &lt;- cbind(col1_x,col2_x,a)
  DF1 &lt;- as.data.frame(DF1, stringsAsFactors = F)
  
  col1_y &lt;- c(012,123,56,55,78,5547)
  col2_y &lt;- c('X1','X8','S2','ER4','KL1','F55')
  b    &lt;- c(111,222,NA,NA,555,666)
  DF2 &lt;- cbind(col1_y,col2_y,b)
  DF2 &lt;- as.data.frame(DF2, stringsAsFactors = F)
  </code></pre>
  <p>Below are the codes which I written for the execution.</p>
  <pre><code># code1
  for (i in 1:nrow(DF2)) { 
    if(is.na(DF2$b[i])) {} else {
      DF1 &lt;-mutate(DF1, 
                   a = ifelse(col1_x == DF2$col1_y[i] &amp; col2_x == DF2$col2_y[i],
                              DF2$b[i],a) )
    }
  }
  
  # code2
  if(is.na(DF2$b)) {} else {
    DF1$a &lt;- ifelse(DF1$col1_x == DF2$col1_y &amp; DF1$col2_x == DF2$col2_y, DF2$b, DF1$a)
  }
  </code></pre>
  <p>I am getting warnings as below when I run code2,</p>
  <pre><code>Warning messages:
  1: In if (is.na(Y$b)) { :
    the condition has length &gt; 1 and only the first element will be used
  2: In X$col1 == Y$col1 :
    longer object length is not a multiple of shorter object length
  3: In X$col2 == Y$col2 :
    longer object length is not a multiple of shorter object length
  </code></pre>
  <p>Kindly help me how can I fix this without using FOR loop as it takes a lot of time for iterations.</p>
  <p><strong>Note: code1 satisfies my requirement</strong></p>