title: How to remove rows from a data.frame when a factor takes particular values in R
body: <p>I am working on a car dataset in R. In that, I have one column named as <code>fuel</code>, which is of class factor. So, total number of cars are distributed in 5 types. I want to remove 3 types from that column. An example is as follows:</p>
  <pre><code>fuel:  
   CNG     :  40                                                                                      
   Diesel  :2133   
   Electric:   1   
   LPG     :  23                          
   Petrol  :2120
  </code></pre>
  <p>How to remove factor levels <code>CNG</code>, <code>Electric</code> &amp; <code>LPG</code> with one command?</p>
  <p>I have tried as below, it works, but I think there is a better way to do, like with a 1 line command.</p>
  <p>1.</p>
  <pre><code>car &lt;- car[!car$fuel == &quot;CNG&quot;, ]
  car &lt;- car[!car$fuel == &quot;Electric&quot;, ]
  car &lt;- car[!car$fuel == &quot;LPG&quot;, ]
  </code></pre>
  <p>I tried following way also, but this did not work, Why did the below command not work?</p>
  <p>2.</p>
  <pre><code>car &lt;- car[!car$fuel == &quot;CNG&quot;||&quot;Electric&quot;||&quot;LPG&quot;, ]
  </code></pre>