Select Subset of Columns based on Vector R : <p>I have a data frame with 300 columns of data. 
I created a vector with 126 elements that are the column names of 126 of the 300.
I want to subset the 300 based on not being in my 126. They are NOT in order, so I can't simply remove by specifying -1:-126.</p>

<p>I tried various things with grep and matrix operations, but they did not work. Such as the following which did not work. x has 300 columns. f contains vector of 126 column names I want to exclude from x1.</p>

<pre><code>x1&lt;-x[,-which(names(x), %in% f)]
</code></pre>

<p>If I definitively use a variable name or several, I can get it to work, but I don't want to type out the 126 elements in f.  </p>
