title: R: no applicable method for 'within' applied to an object of class "character
body: <p>I am trying to loop through data frames and recode all values of a specific named variable to NA for all data frames. This should return the separate data frames with the specified variable's values coded NA.</p>
  
  <p>I tried using within() for this but I receive an error:</p>
  
  <p><strong>Error in UseMethod("within") : 
    no applicable method for 'within' applied to an object of class "character"</strong> </p>
  
  <p>A minimal working example is found below:</p>
  
  <pre><code># Create df
  a &lt;- data.frame(seq(1:10), rep("x"))
  b &lt;- data.frame(seq(1:10), rep("y"))
  
  # Rename vars for easy reference
  colnames(a) &lt;- c("num", "string")
  colnames(b) &lt;- c("num", "string")
  
  # Create vector of variables names
  vars &lt;- c("a", "b")
  
   # Loop through data frames and replace values of "string" with NA\
   for (i in vars){
        i &lt;- within(i, {string &lt;- NA})
        }
  </code></pre>
  
  <p>Note: this is most relevant to <a href="https://stackoverflow.com/questions/30757856/error-in-usemethodmeta-x-no-applicable-method-for-try-error-applied-to">Error in UseMethod(&quot;meta&quot;, x) : no applicable method for &#39;try-error&#39; applied to an object of class &quot;character&quot;</a> which remains largely unanswered.</p>