title: access data frame column using variable
body: <p>Consider the following code</p>
  
  <pre><code>a = "col1"
  b = "col2"
  d = data.frame(a=c(1,2,3),b=c(4,5,6))
  </code></pre>
  
  <p>This code produces the following data frame</p>
  
  <pre><code>  a b
  1 1 4
  2 2 5
  3 3 6
  </code></pre>
  
  <p>However the desired data frame is</p>
  
  <pre><code>  col1 col2
  1 1    4
  2 2    5
  3 3    6
  </code></pre>
  
  <p>Further, I'd like to be able to do something like <code>d$a</code> which would then grab <code>d$col1</code> since <code>a = "col1"</code></p>
  
  <p>How can I tell R that <code>"a"</code> is a variable and not a name of a column?</p>