title: Pass column name in data.table using variable
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/12391950/variably-selecting-assigning-to-fields-in-a-data-table">Variably selecting/assigning to fields in a data.table</a>  </p>
  </blockquote>
  
  
  
  <p>In following example, I am creating a data table having column name ‘x’ and ‘v’</p>
  
  <pre><code>library('data.table')
  DT &lt;- data.table(x = c("b","b","b","a","a"), v = rnorm(5))
  </code></pre>
  
  <p>I can access values of column ‘x’ by :</p>
  
  <pre><code>DT[ , x]
  # [1] "b" "b" "b" "a" "a"
  </code></pre>
  
  <p>But if I want to access by passing through a variable, it doesn’t work</p>
  
  <pre><code>temp &lt;- "x"
  DT[ , temp]
  # [1] "x"
  </code></pre>
  
  <p>There would be multiple columns and I will have to select values for only couple of them. These column names I will be provide by passing through a R module.</p>
  
  <p>Never mind, I got it, it should be: </p>
  
  <pre><code>DT[ , get(temp)]
  </code></pre>