title: How to Reorder Formal Class Spatial Polygons
body: <p>I'm looking for a way to re-order a set of Formal Class Spatial Polygons using</p>
  
  <p>I'm using US Census data (Limited to Texas) and want to create 33 polygons out of different county combinations. </p>
  
  <pre><code>library(tmap)
  library(maptools)
  library(ggplot2)
  library(rgeos)
  library(sp)
  library(mapdata)
  library(rgdal)
  library(raster)
  
  # Download the map of texas and get the LMAs boundaries
  #   Download shape
  f &lt;- tempfile()
  download.file("http://www2.census.gov/geo/tiger/GENZ2010/gz_2010_us_050_00_20m.zip", destfile = f)
  unzip(f, exdir = ".")
  US &lt;- read_shape("gz_2010_us_050_00_20m.shp")
  
  #   Select only Texas
  Texas &lt;- US[(US$STATE %in% c("48")),]
  
  
  #   Load the LMA append data
  LMAs = read.table('LMA append data.csv',header=T, sep=',')
  
  #   Append LMA data to Texas shape
  Texas$FIPS &lt;- paste0(Texas$STATE, Texas$COUNTY)
  Texas &lt;- append_data(Texas, LMAs, key.shp = "FIPS", key.data = "FIPS")
  Texas &lt;- Texas[order(Texas$LMA),]
  
  #   Create shape object with LMAs polygons
  Texas_LMA &lt;- unionSpatialPolygons(Texas, IDs=Texas$LMA)
  </code></pre>
  
  <p>I've tried converting Texas_LMA into a SpatialPolygonsDataFrame with </p>
  
  <pre><code>#   Create shape object with LMAs polygons
  Texas_LMA &lt;- unionSpatialPolygons(Texas, IDs=Texas$LMA)
  spp &lt;- SpatialPolygonsDataFrame(Texas_LMA,data=matrix(1:33,nrow=33,ncol=1))
  </code></pre>
  
  <p>But that hasn't worked for me. </p>