title: Concatenate pairs of variables with same suffix
body: <p>I have a data frame that has a number of variables in it that I want to concatenate into new variables in that same data frame. A simplified version of my data frame <em>df</em> looks like this:</p>
  
  <pre><code>first.1 second.1 first.2 second.2 
  1222 3223 3333 1221 
  1111 2212 2232 2113 
  </code></pre>
  
  <p>Here is how I do it inefficiently without a for loop:</p>
  
  <pre><code>df$concatenated.1 &lt;- paste0(df$first.1,"-",df$second.1)
  df$concatenated.2 &lt;- paste0(df$first.2,"-",df$second.2)
  </code></pre>
  
  <p>Which results in the following data frame <em>df</em>:</p>
  
  <pre><code>first.1 second.1 first.2 second.2 concatenated.1 concatenated.2 
  1222 3223 3333 1221 1222-3223 3333-1221 
  1111 2212 2232 2113 1111-2212 2232-2113 
  </code></pre>
  
  <p>I have a lot more than 2 pairs of variables to concatenate, so I would like to do this in a for loop:</p>
  
  <pre><code>for (i in 1:2){
  ??
  }
  </code></pre>
  
  <p>Any ideas on how to accomplish this?</p>