title: How can I eliminate some areas by attribute from a shapefile in R and create a new shapefile?
body: <p>I have been at this for a while now and have had some success, however when it comes to rewriting the file, I have had none. </p>
  
  <p>The shapefile I am working with is a polygon shapefile of metro and micropolitan areas but I am not interested in the micropolitan areas so I am working with the shp in R to try and eliminate them from my map. </p>
  
  <p><a href="http://www.census.gov/cgi-bin/geo/shapefiles2010/layers.cgi" rel="noreferrer">Data Source</a></p>
  
  <p>To download the right file, make sure that you select "All States in one national file" under "Metropolitan/Micropolitan Statistical Area (2010)"</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>library(maptools)
  met=readShapeSpatial("tl_2010_us_cbsa10.shp")
  met=met@data
  </code></pre>
  
  <p>Before subset:</p>
  
  <pre><code>NAMELSAD10      LSAD10
  Anchorage, AK Metro Area   -  M1 
  Clarksdale, MS Micro Area    - M2
  Richmond, VA Metro Area   -  M1
  Big Spring, TX Micro Area  -   M2
  Dallas-Fort Worth-Arlington, TX Metro Area  -   M1
  Rio Grande City-Roma, TX Micro Area  -   M2
  </code></pre>
  
  <p>then:</p>
  
  <pre><code>submet=subset(met, LSAD10 == "M1")
  </code></pre>
  
  <p>After subset:</p>
  
  <pre><code>NAMELSAD10 LSAD10
  Anchorage, AK Metro Area   -  M1
  Richmond, VA Metro Area  -   M1
  Dallas-Fort Worth-Arlington, TX Metro Area   -  M1
  Vineland-Millville-Bridgeton, NJ Metro Area  -   M1
  Casper, WY Metro Area   -  M1
  Cheyenne, WY Metro Area   -  M1
  </code></pre>
  
  <p>then:</p>
  
  <pre><code>writeSpatialShape(submet, "tl_2010_us_ma10", factor2char = TRUE)
  </code></pre>
  
  <p>Using this code I have been able to successfully eliminate the Micropolitan areas designated "M1" but when I try to rewrite the file, it doesn't show up in my wd.</p>
  
  <p>I have also attempted using the package "shapefiles" to get this done but had even less success. So any help in this matter would be greatly appreciated. </p>