title: R - assign unique ID to each Spatial_DataFrame element in a list
body: <p>I have a list of many <code>SpatialLinesDataFrames</code>. I want to add a column to each SLDF that has an ID equivalent to the list index ID (i.e., every row in each individual SLDFs new column will have the same ID). I would like the solution to be workable to any kind of <code>sp</code> Spatial DataFrame object (polygons, points, etc).</p>
  
  <p>Based on a solution for simple data.frames (<a href="https://stackoverflow.com/questions/55638951/r-assign-unique-id-to-each-data-frame-element-in-a-list">Assign unique ID to each data.frame element in a list</a>), I tried this with the following example code:</p>
  
  <pre><code>library(raster)
  #create list of single-feature `SpatialLineDataFrame`
  l1 &lt;- cbind(c(0,3), c(0,3))
  l2 &lt;- cbind(c(0, 13), c(0, 1))
  l3 &lt;- cbind(c(0, 24), c(0,22.5))
  l4 &lt;- cbind(c(0, 1), c(0,13))
  l5 &lt;- cbind(c(0, 6), c(0,6))
  Sldf &lt;- spLines(l1, l2, l3, l4, l5, attr=data.frame(lineID=1:5))
  
  #make individual list elements
  sldfl &lt;- list()
  sldfl[[1]] &lt;- Sldf[1,]
  sldfl[[2]] &lt;- Sldf[2,]
  sldfl[[3]] &lt;- Sldf[3,]
  sldfl[[4]] &lt;- Sldf[4,]
  sldfl[[5]] &lt;- Sldf[5,]
  
  #attempt to add new column with unique index id
  newlist &lt;- Map(cbind,sldfl, unique.id = (1:length(sldfl)))
  </code></pre>
  
  <p>I want the column name to be "unique.id" and the same for all elements, but the results are element-specific and not the name I specify (i.e., X1L, X2L, etc) as follows:</p>
  
  <pre><code>[[1]]
  class       : SpatialLinesDataFrame 
  features    : 1 
  extent      : 0, 3, 0, 3  (xmin, xmax, ymin, ymax)
  coord. ref. : NA 
  variables   : 2
  names       : lineID, X1L 
  value       :      1,   1 
  
  [[2]]
  class       : SpatialLinesDataFrame 
  features    : 1 
  extent      : 0, 13, 0, 1  (xmin, xmax, ymin, ymax)
  coord. ref. : NA 
  variables   : 2
  names       : lineID, X2L 
  value       :      2,   2 
  </code></pre>
  
  <p>But I want this:</p>
  
  <pre><code>[[1]]
  class       : SpatialLinesDataFrame 
  features    : 1 
  extent      : 0, 3, 0, 3  (xmin, xmax, ymin, ymax)
  coord. ref. : NA 
  variables   : 2
  names       : lineID, unique.id 
  value       :      1,   1 
  
  [[2]]
  class       : SpatialLinesDataFrame 
  features    : 1 
  extent      : 0, 13, 0, 1  (xmin, xmax, ymin, ymax)
  coord. ref. : NA 
  variables   : 2
  names       : lineID, unique.id 
  value       :      2,   2
  </code></pre>