title: Select subset of columns in data.table R
body: <p>I have a data table with a bunch of columns, e.g.:</p>
  
  <pre><code>dt&lt;-data.table(matrix(runif(10*10),10,10))
  </code></pre>
  
  <p>I want to perform some operation on the data table, such as producing a correlation matrix (<code>cor(dt)</code>). In order to do this, I want to remove a few columns that contain non-numeric values or values outside a certain range.</p>
  
  <p>Let's say I want to find the correlation matrix excluding V1, V2, V3 and V5. </p>
  
  <p>Here is my current approach:</p>
  
  <pre><code>cols&lt;-!(colnames(dt)=="V1" | colnames(dt)=="V2" | colnames(dt)=="V3" | colnames(dt)=="V5")
  new_dt&lt;-subset(dt,,cols)
  cor(new_dt)
  </code></pre>
  
  <p>I find this pretty cumbersome, considering data.table syntax is usually so elegant. Is there a better method of doing this?</p>