title: Create new variable for many columns in R
body: <p>Say I have some data and I want to do a loop for multiple variables where I subtract '1' from oldvariable and create a new variable that adds 'p' to the original variable name. Here is some data. So say I have var1 and var2 and want to create var1p and var2p where var1p = var1 - 1. How can I loop this for many variables? Below the data is my attempt but it does not get the job done. I could subtract '1' but am not sure how to append to the df new variable names with these values.</p>
  
  <pre><code>df &lt;- read.table(text =
                     "id var1 var2 var2p  var3p group
                   1  12    3    11   2    1
                   2  8     6    7   5    1
                   3  25    30   24   5    2
                   4  26    31   25   30    2
                   5  22    29   21   28    2", header = T)
  
  
  new_data &lt;- data.frame(lapply(df, function(x) x-1))
  </code></pre>