title: Aggregate POLYGONs to MULTIPOLYGONs and keep data.frame
body: <p>I have a <code>sf</code> object of POLYGON geometry type. I would like to aggregate these polygons into MULTIPOLYGONs using grouping attribute (group_attr) and join a new MULTIPOLYGON object with a attribute table. So, as a result, I will have a <code>sf</code> object with two rows and three columns (group_attr, second_attr, geometry). I've already tried to used <code>st_cast</code> - it works well on <code>sfc</code> objects, but not on <code>sf</code> objects. Is it possible to do this using <code>sf</code> package?</p>
  
  <pre><code>p1 &lt;- rbind(c(0,0), c(1,0), c(3,2), c(2,4), c(1,4), c(0,0))
  pol1 &lt;-st_polygon(list(p1))
  p2 &lt;- rbind(c(3,0), c(4,0), c(4,1), c(3,1), c(3,0))
  pol2 &lt;-st_polygon(list(p2))
  p3 &lt;- rbind(c(4,0), c(4,1), c(5,1), c(5,0),c(4,0))
  pol3 &lt;-st_polygon(list(p3))
  p4 &lt;- rbind(c(3,3), c(4,2), c(4,3), c(3,3))
  pol4 &lt;-st_polygon(list(p4))
  
  d &lt;- data.frame(group_attr = c(1, 1, 2, 2), 
                  second_attr = c('forest', 'forest', 'lake', 'lake'))
  d$geometry &lt;- st_sfc(pol1, pol2, pol3, pol4)
  df&lt;- st_as_sf(d)
  plot(df)
  df
  
  Simple feature collection with 4 features and 2 fields
  geometry type:  POLYGON
  dimension:      XY
  bbox:           xmin: 0 ymin: 0 xmax: 5 ymax: 4
  epsg (SRID):    NA
  proj4string:    NA
    group_attr second_attr                       geometry
  1          1      forest POLYGON((0 0, 1 0, 3 2, 2 4...
  2          1      forest POLYGON((3 0, 4 0, 4 1, 3 1...
  3          2        lake POLYGON((4 0, 4 1, 5 1, 5 0...
  4          2        lake  POLYGON((3 3, 4 2, 4 3, 3 3))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/wEq6l.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wEq6l.png" alt="enter image description here"></a></p>