title: Replace values in selected columns by passing column name of data.frame into apply() or plyr function
body: <p>Suppose I have a date.frame like:</p>
  
  <pre><code>df &lt;- data.frame(a=1:5, b=sample(1:5, 5, replace=TRUE), c=5:1)
  df
    a b c
  1 1 4 5
  2 2 3 4
  3 3 5 3
  4 4 2 2
  5 5 1 1
  </code></pre>
  
  <p>and I need to replace all the <code>5</code> as <code>NA</code> in column <code>b</code> &amp; <code>c</code> then return to <code>df</code>:</p>
  
  <pre><code>df
    a b  c
  1 1 4  NA
  2 2 3  4
  3 3 NA 3
  4 4 2  2
  5 5 1  1
  </code></pre>
  
  <p>But I want to do a generic <code>apply()</code> function instead of using <code>replace()</code> each by each because there are actually many variables need to be replaced in the real data. Suppose I've defined a variable list:</p>
  
  <pre><code>var &lt;- c("b", "c")
  </code></pre>
  
  <p>and come up with something like:</p>
  
  <pre><code>df &lt;- within(df, sapply(var, function(x) x &lt;- replace(x, x==5, NA)))
  </code></pre>
  
  <p>but nothing happens. I was thinking if there is a way to work this out with something similar to the above by passing a variable list of column names from a data.frame into a generic <code>apply / plyr</code> function (or maybe some other completely different ways). Thanks~</p>