title: R variable names in loop, get, etc
body: <p>Still relatively new to R. Trying to have dynamic variables in a loop but running into all sorts of problems. Initial code looks something like this (but bigger)</p>
  
  <pre><code>data.train$Pclass_F &lt;- as.factor(data.train$Pclass)
  data.test$Pclass_F &lt;- as.factor(data.test$Pclass)
  </code></pre>
  
  <p>which I'm trying to build into a loop, imagining something like this</p>
  
  <pre><code>datalist &lt;- c("data.train", "data.test")
  for (i in datalist){
    i$Pclass_F &lt;- as.factor(i$Pclass)
  }
  </code></pre>
  
  <p>which doesn't work. A little research implies that inorder to convert the string <code>datalist</code> into a variable I need to use the <code>get</code> function. So my next attempt was </p>
  
  <pre><code>datalist &lt;- c("data.train", "data.test")
  for (i in datalist){
    get(i$Pclass_F) &lt;- as.factor(get(i$Pclass))
  }
  </code></pre>
  
  <p>which still doesn't work <code>Error in i$Pclass : $ operator is invalid for atomic vectors</code>. Tried</p>
  
  <pre><code>datalist &lt;- c("data.train", "data.test")
  for (i in datalist){
    get(i)$Pclass_F &lt;- as.factor(get(i)$Pclass)
  }
  </code></pre>
  
  <p>which still doesn't work <code>Error in get(i)$Pclass_F &lt;- as.factor(get(i)$Pclass) : 
    could not find function "get&lt;-"</code>. Even tried</p>
  
  <pre><code>datalist &lt;- c("data.train", "data.test")
  for (i in datalist){
    get(i[Pclass_F]) &lt;- as.factor(get(i[Pclass]))
  }
  </code></pre>
  
  <p>which still doesn't work <code>Error in get(i[Pclass]) : object 'Pclass' not found</code>. The tried</p>
  
  <pre><code>datalist &lt;- c("data.train", "data.test")
  for (i in datalist){
    get(i)[Pclass_F] &lt;- as.factor(get(i)[Pclass])
  }
  </code></pre>
  
  <p>which still doesn't work <code>Error in '[.data.frame'(get(i), Pclass) : object 'Pclass' not found</code></p>
  
  <p>Now realized I never included data so nobody can run this themselves, but just to show it's not a data problem</p>
  
  <pre><code>&gt; class(data.train$Pclass)
  [1] "integer"
  &gt; class(data.test$Pclass)
  [1] "integer"
  &gt; datalist
  [1] "data.train" "data.test" 
  </code></pre>