R dplyr: Drop multiple columns
<p>I have a dataframe and list of columns in that dataframe that I'd like to drop. Let's use the <code>iris</code> dataset as an example. I'd like to drop <code>Sepal.Length</code> and <code>Sepal.Width</code> and use only the remaining columns. How do I do this using <code>select</code> or <code>select_</code> from the <code>dplyr</code> package?</p>

<p>Here's what I've tried so far:</p>

<pre><code>drop.cols &lt;- c('Sepal.Length', 'Sepal.Width')
iris %&gt;% select(-drop.cols)
</code></pre>

<blockquote>
  <p>Error in -drop.cols : invalid argument to unary operator</p>
</blockquote>

<pre><code>iris %&gt;% select_(.dots = -drop.cols)
</code></pre>

<blockquote>
  <p>Error in -drop.cols : invalid argument to unary operator</p>
</blockquote>

<pre><code>iris %&gt;% select(!drop.cols)
</code></pre>

<blockquote>
  <p>Error in !drop.cols : invalid argument type</p>
</blockquote>

<pre><code>iris %&gt;% select_(.dots = !drop.cols)
</code></pre>

<blockquote>
  <p>Error in !drop.cols : invalid argument type</p>
</blockquote>

<p>I feel like I'm missing something obvious because these seems like a pretty useful operation that should already exist. On Github, someone posted <a href="https://github.com/hadley/dplyr/issues/231">a similar issue</a>, and Hadley said to use 'negative indexing'. That's what (I think) I've tried, but to no avail. Any suggestions?</p>