R - Getting Column of Dataframe from String : <p>I am trying to create a function that allows the conversion of selected columns of a data frame to categorical data type (factor) before running a regression analysis.</p>

<p>Question is how do I slice a particular column from a data frame using a string (character).</p>

<p>Example:</p>

<pre><code>  strColumnNames &lt;- "Admit,Rank"
  strDelimiter &lt;- ","
  strSplittedColumnNames &lt;- strsplit(strColumnNames, strDelimiter)
  for( strColName in strSplittedColumnNames[[1]] ){
    dfData$as.name(strColName) &lt;- factor(dfData$get(strColName))
  }
</code></pre>

<p>Tried:</p>

<pre><code>dfData$as.name()
dfData$get(as.name())
dfData$get()
</code></pre>

<p>Error Msg:
Error: attempt to apply non-function</p>

<p>Any help would be greatly appreciated! Thank you!!!</p>
