title: Introduce two strings in a "for" loop
body: <p>I have this dataframe:</p>
  <pre><code>a &lt;- c(2,5,90,77,56,65,85,75,12,24,52,32)
  b &lt;- c(45,78,98,55,63,12,23,38,75,68,99,73)
  c &lt;- c(77,85,3,22,4,69,86,39,78,36,96,11)
  d &lt;- c(52,68,4,25,79,120,97,20,7,19,37,67)
  e &lt;- c(14,73,91,87,94,38,1,685,47,102,666,74)
  
  df &lt;- data.frame(a,b,c,d,e)
  </code></pre>
  <p>and this script:</p>
  <pre><code>R &lt;- Map(`+`, list(1:3), 0:9) 
  cmin &lt;- t(as.matrix(rep(NA, ncol(df)))) 
  
  for (r in seq(R)) {
    for (f in seq(ncol(df))) {
      x &lt;- df[R[[r]], f]
      y &lt;- df[R[[r]], -f]
      dif_2 &lt;- (x - y)^2
      cmin[f] &lt;- which.min(colSums(dif_2))
    }
  }
  
  dif_3 &lt;- as.matrix(dif_2[,cmin])
  sq &lt;- sqrt(dif_3)
  </code></pre>
  <p>How can I put the last two lines of the script into the &quot;for&quot; loop above?</p>
  <p>Thanks everyone for helping me!</p>