title: R sf: Find polygons outside of multiple overlapping polygons
body: <p>I have a large shapefile that contains 1000s of multiple, overlapping polygons. I am trying to the combined area outside of these multiple, overlapping polygons that do not overlap with any polygon in the layer. These are effectively regions where fires have burned multiple times, I am looking for where fires have only burned once.</p>
  <p>I am stuck on how to find the area outside that does not have any overlaps. Can you help?</p>
  <p>Here is a reproducible example.</p>
  <pre><code>#make some overlapping polygons
  m = rbind(c(0,0), c(1,0), c(1,1), c(0,1), c(0,0))
  p = st_polygon(list(m))
  n = 100
  l = vector(&quot;list&quot;, n)
  for (i in 1:n)
    l[[i]] = p + 2 * runif(2)
  s = st_sfc(l)
  
  #select just a few of these
  s5 &lt;- s[1:5]
  
  #now try to step through and get the non-overlapping areas
  counter &lt;- 0
  sall.out &lt;- list()
  for (i in 1:length(s5)) {
      print(i)
      s5.sel &lt;- s5[i]
      s5.out &lt;- s5[!(s5 == s5.sel)] #select all the polygons outside
      s5.int &lt;- st_intersection(s5.out, s5.sel) #intersect the outside polygons with the one selected
  
      #step through and find all differences between the selected region and the intersected
      for (j in 1:length(s5.int)) {
          print(j)
          s5.out &lt;- st_difference(s5.sel, s5.int[j])
      
          counter &lt;- counter+1
          sall.out[[counter]] &lt;- s5.out
      }
  }
  
  plot(s5)
  plot(s5.sel, add=T, col=&quot;red&quot;)
  plot(s5.int, add=T, col=&quot;blue&quot;)
  plot(s5.out, add=T, col=&quot;pink&quot;)
  
  </code></pre>
  <p>So, now I have all of the sall.out in a list, but how can I remove the ones that overlap each other and flatten the list?</p>
  <p>Thank you.</p>