title: SpatialPolygons - Creating a set of polygons in R from coordinates
body: <p>I am trying to take create a set of polygons from vertex locations, saved in X,Y format.</p>
  
  <p>Here is an example of my data - each row represents the vertices for one polygon. the polygons are squares</p>
  
  <pre><code>square &lt;- rbind(c(255842.4, 4111578, 255862.4, 4111578, 255862.4, 4111558, 
                    255842.4, 4111558, 255842.4, 4111578, 255842.4, 4111578),
                  c(257397.0, 4111309, 257417.0, 4111309, 257417.0, 4111289, 
                    257397.0, 4111289, 257397.0, 4111309, 257397.0, 4111309))
  
  ID &lt;- c("SJER1", "SJER2")'
  </code></pre>
  
  <p>I am using <code>SpatialPolygons</code>, thus my data need to be in a list. so i created a loop to attempt to get my data into a list format from a matrix.</p>
  
  <p>I create a loop following code that I found in some other questions on this site. I broke out each step to try to understand why i am only getting one polygon as the output even through I have 2 sets of points. </p>
  
  <pre><code>for (i in 1:2) {  
    pts &lt;- rbind(c(square[i,1], square[i,2]), c(square[i,3], square[i,4]), 
                 c(square[i,5],square[i,6]), c(square[i,7],square[i,8]), 
                 c(square[i,9],square[i,10]))
    sp1 &lt;- list(Polygon(pts))
    sp2 &lt;- list(Polygons(sp1,i))
    sp = SpatialPolygons(sp2)  
  }
  plot(sp)
  </code></pre>
  
  <p>Can you please help me understand how I adjust the code to write out two polygons instead of just one? And also, how I assign the ID to each polygon given I am using a matrix (square) as my starting dataset and if I assign a character id, it transforms all of my data into a character.</p>
  
  <p>My ultimate goal is two polygons in the <code>SpatialPolygons</code> object, the first with the ID <code>SJER1</code> and the second with the ID <code>SJER2</code> stored in the <code>SpatialPolygons</code> object.</p>
  
  <p>Then I will write this out to a shapefile.</p>