title: Deleting/Subsetting Rows in R by setdiff/intersect
body: <p>I am trying to delete rows out of my data set that contain certain vegetation types. I want to delete the rows from my unsurveyed data that have vegetation types not found in my surveyed data. I found a way to do this but am looking for a one-line method. I am currently doing this:</p>
  
  <pre><code>&gt; setdiff(unsurveyed_1$VEGETATION, surveyed_1$VEGETATION)
  </code></pre>
  
  <p>Which returns seven vegetation types that I then delete doing this:</p>
  
  <pre><code>&gt; unsurveyed_1 &lt;- unsurveyed_1[!unsurveyed_1$VEGETATION == "Acer rubrum- Nyssa sylvatica saturated forest alliance",]
  &gt; unsurveyed_1 &lt;- unsurveyed_1[!unsurveyed_1$VEGETATION == "Acer rubrum/Quercus coccinea-Acer rubrum-Vaccinium corybosum-Vaccinium palladium",]
  &gt; unsurveyed_1 &lt;- unsurveyed_1[!unsurveyed_1$VEGETATION == "Building",]
  &gt; unsurveyed_1 &lt;- unsurveyed_1[!unsurveyed_1$VEGETATION == "Parking Lot",]
  &gt; unsurveyed_1 &lt;- unsurveyed_1[!unsurveyed_1$VEGETATION == "Prunus serotina",]
  &gt; unsurveyed_1 &lt;- unsurveyed_1[!unsurveyed_1$VEGETATION == "Typha (angustifolia, latifolia) - (Schoenoplectus spp.) Eastern Herbaceous Vegetation",]
  &gt; unsurveyed_1 &lt;- unsurveyed_1[!unsurveyed_1$VEGETATION == "Water",]
  </code></pre>
  
  <p>I tried a few different options including subsetting with little success so far figuring that would be my best option. I am also looking to something similar with intersect but am assuming that it would similar answers.</p>
  
  <p>EDIT: 
  In addition to using the code that @Cath supplied I edited it to get the opposite as well. </p>
  
  <pre><code>&gt; unsurveyed_2 &lt;- unsurveyed_2[unsurveyed_2$VEGETATION %in% setdiff(unsurveyed_2$VEGETATION, surveyed_1$VEGETATION), ]
  </code></pre>