title: How to dynamically rename columns in a function in R?
body: <p>Here is a function I'm trying to build in R</p>
  
  <pre><code>lag_decay_gen &lt;- function(data,col,lag_val,decay_val)
    {
    temp &lt;- lag(col, n = lag_val*7, default =0)
    temp &lt;- temp + shift(temp)*decay_val
    temp &lt;- cbind(data,temp)
    }
  </code></pre>
  
  <p>Here data = main dataset while col = column of the dataset</p>
  
  <p>Generally, the input for col would something look like this - data$'column_name'</p>
  
  <p>Here inside the function I would like the temp column to be renamed dynamically to </p>
  
  <pre><code>paste(col,lag_val,decay_val, sep = "_")
  </code></pre>
  
  <p>where col is the name of the column but this is the value under the column that I'm passing to the function and hence an error occurs. </p>
  
  <p>Moreover, how should I go about building the function lag_decay_gen if my col input has multiple columns. Any help would be much appreciated.</p>