title: How can R loop over data frames?
body: <p>Suppose there are many data frames that need the same operation performed on them. For example: </p>
  
  <pre><code>prefix &lt;- c("Mrs.","Mrs.","Mr","Dr.","Mrs.","Mr.","Mrs.","Ms","Ms","Mr")
  measure &lt;- rnorm(10)
  df1 &lt;- data.frame(prefix,measure)
  df1$gender[df1$prefix=="Mrs."] &lt;- "F"
  </code></pre>
  
  <p>Would create an indicator variable called gender when the value in the adjacent row was "Mrs.". A general way to loop over string variables in R was adapted from <a href="https://stackoverflow.com/questions/1663370/loop-over-string-variables-in-r">here</a> with the function <code>as.name()</code> added to remove the quotes from "i":</p>
  
  <pre><code>dflist &lt;- c("df1","df2","df3","df4","df5")
  
  for (i in dflist) { 
    as.name(i)$gender[as.name(i)$prefix=="Ms."] &lt;- "F"
    }
  </code></pre>
  
  <p>Unfortunately this doesn't work. Any suggestions? </p>