title: In R, how do I join and subset SpatialPolygonsDataFrame?
body: <p>I'm trying to figure out my way on how to perform (so easy in GIS) operations in R.</p>
  
  <p>Let's take some example polygon data set from <code>spdep</code> package</p>
  
  <pre><code>library("spdep")
  c &lt;- readShapePoly(system.file("etc/shapes/columbus.shp", package="spdep")[1])
  plot(c)
  </code></pre>
  
  <p>I've managed to figure out that I can choose polygons with logical statements using <code>subset</code>. For instance:</p>
  
  <blockquote>
    <p>cc &lt;- subset(c, c@data$POLYID&lt;5) plot(cc)</p>
  </blockquote>
  
  <p>Now, let's suppose I have another data frame that I'd like to join to my spatial data:</p>
  
  <pre><code>POLYID=1:9
  TO.LINK =101:109
  link.data &lt;- data.frame(POLYID=POLYID, TO.LINK=TO.LINK)
  </code></pre>
  
  <p>Using these two datasets, how can I get two spatial data frames:</p>
  
  <ol>
  <li>First, consisting of polygons that have their ID in the second data frame</li>
  <li>Second, consisting of the opposite set - polygons that do not exist in the second data frame.</li>
  </ol>
  
  <p>How could I get to this point?</p>