title: create new column by adding two columns in r within for loop
body: <p>Let's say I have sample dataframe (df) :</p>
  
  <pre><code>id col1 col2 col3 col4 col5 col6
   1   2    3    2    6    2    8
   2   3    2    4    1    3    2 
   3   4    2    9    7    8    7 
   4   7    6    3    2    9    2
  </code></pre>
  
  <p>Now I am trying to add 2 columns at a time and create new column i.e col1+col2, col3+col4, col5+col6</p>
  
  <p>Desired output:</p>
  
  <pre><code>id col1 col2 col3 col4 col5 col6 t_1 t_3 t_5
   1   2    3    2    6    2    8    5   8   10
   2   3    2    4    1    3    2    5   5   5
   3   4    2    9    7    8    7    6   16  15
   4   7    6    3    2    9    2    13  5   11
  </code></pre>
  
  <p>I wrote following code:</p>
  
  <pre><code>for(i in c(1, 3, 5)){
  paste('df$t', i, sep= '_') &lt;- as.numeric(df[, i]) + as.numeric(df[, i+1])
  }
  </code></pre>
  
  <p>but i get following error:</p>
  
  <blockquote>
    <p>Error in paste("df$t", i, sep = "_") &lt;- as.numeric(df[,  : 
      target of assignment expands to non-language object`</p>
  </blockquote>
  
  <p>Am I doing something wrong here ?</p>