title: Adding columns to a data table
body: <p>I have a data.frame (or a matrix or any other tabular data structure object for that matter):</p>
  
  <pre><code>df = data.frame(field1 = c(1,1,1),field2 = c(2,2,2),field3 = c(3,3,3))
  </code></pre>
  
  <p>And I want to copy part of its columns - given in the vector below:</p>
  
  <pre><code>fields = c("field1","field2")
  </code></pre>
  
  <p>to a new data.table that already has 1 or more columns:</p>
  
  <pre><code>dt = data.table(fieldX = c("x","x","x"))
  </code></pre>
  
  <p>I'm looking for something more efficient (and elegant) than:</p>
  
  <pre><code>for(f in 1:length(fields))
  {
  dt[,fields[f]] = df[,fields[f]]
  }
  </code></pre>