title: R - pass column name as variable to lapply
body: <p>I'm applying this function to a list in R.</p>
  
  <pre><code>tmp&lt;-lapply(mydata,transform, V3 = ifelse(V2 &gt; 20, V3, NA))
  </code></pre>
  
  <p>Each element in the list is a dataframe with 3 numeric columns V1, V2 and V3. The code above works just fine.</p>
  
  <p>But if I try to set the columns as variables:</p>
  
  <pre><code>colA&lt;-paste("V",2,sep="")
  colB&lt;-paste("V",3,sep="")
  </code></pre>
  
  <p>and then:</p>
  
  <pre><code>tmp&lt;-lapply(mydata,transform, colB = ifelse(colA &gt; 20, colB, NA))
  </code></pre>
  
  <p>this doesn't work. It creates a new column named "colB" fill with "V3" string.</p>
  
  <p>I also tried with get:</p>
  
  <pre><code>tmp&lt;-lapply(mydata,transform, get(colB) = ifelse(get(colA) &gt; 20, get(colB), NA))
  Error: unexpected '=' in "tmp&lt;-lapply(mydata,transform, get(colB) ="
  </code></pre>
  
  <p>Is there any way to pass a variable with the column name in R?
  The final aim is that colA and colB are passed as command line arguments when calling the script with Rscript because the same code could be applied to different lists with variable number of columns.
  Thanks</p>