Using column names of data.frame
<p>I have the following (simplified) text file, which is named <code>datafile.txt</code>:</p>

<pre><code>Height Color Sales     
short blue 24    
short blue 25   
short red 31   
short red 28   
short black 35   
short black 32   
tall blue 31   
tall blue 32   
tall red 36   
tall red 32   
tall black 41   
tall black 36   
</code></pre>

<p>From this text file, I create the data.frame <code>data</code>:</p>

<pre><code>data &lt;- read.table("datafile.txt", header = TRUE)
</code></pre>

<p>By the following line, I can perform a two-way <em>ANOVA</em>:</p>

<pre><code>anova(lm(Sales ~ Height*Color, data))
</code></pre>

<p>However, the following code, which I expected to perform a two-way <em>ANOVA</em>, does not work:</p>

<pre><code>columnNames &lt;- names(data)    
anova(lm(columnNames[3] ~ columnNames[1]*columnNames[2], data))
</code></pre>

<p>I would like to perform the analysis by using the column names extracted from the data.frame, not by directly typing <code>Sales</code>, <code>Height</code> and <code>Color</code>.  I will very much appreciate your help.</p>