title: Selecting columns in R data frame based on those *not* in a vector
body: <p>I'm familiar with being able to extract columns from an R data frame (or matrix) like so:</p>
  
  <pre><code>df.2 &lt;- df[, c("name1", "name2", "name3")]
  </code></pre>
  
  <p>But can one use a <code>!</code> or other tool to select <em>all but those listed columns</em>?</p>
  
  <p>For background, I have a data frame with quite a few column vectors and I'd like to avoid:</p>
  
  <ul>
  <li>Typing out the majority of the names when I could just remove a minority</li>
  <li>Using the much shorter <code>df.2 &lt;- df[, c(1,3,5)]</code> because when my .csv file changes, my code goes to heck since the numbering isn't the same anymore. I'm new to R and think I've learned the hard way not to use number vectors for larger df's that might change.</li>
  </ul>
  
  <p>I tried:</p>
  
  <pre><code>df.2 &lt;- df[, !c("name1", "name2", "name3")]
  df.2 &lt;- df[, !=c("name1", "name2", "name3")]
  </code></pre>
  
  <p>And just as I was typing this, found out that this works:</p>
  
  <pre><code>df.2 &lt;- df[, !names(df) %in% c("name1", "name2", "name3")]
  </code></pre>
  
  <p>Is there a better way than this last one?</p>