As of dplyr (0.8.3) and sf (0.8.0), the following was possible (see https://stackoverflow.com/a/49354480/9164265):
library(dplyr)
library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
nc %>%
group_by(SID74) %>%
summarise(geometry = st_union(geometry)) %>%
ungroup()
This would have had the effect of combining each geometry with the same SID74
into their own MULTIPOLYGON
s.
However, this now (dplyr 1.0.0) gives the following error:
Error: Problem with `summarise()` input `geometry`.
x Input `geometry` must return compatible vectors across groups
ℹ Input `geometry` is `st_union(geometry)`.
ℹ Result type for group 1 (SID74 = 0): <sfc_MULTIPOLYGON>.
ℹ Result type for group 2 (SID74 = 1): <sfc_MULTIPOLYGON>.
Run `rlang::last_error()` to see where the error occurred.
Does anyone know why dplyr is throwing this error, despite the types evidently being of the same <sfc_MULTIPOLYGON>
class?
Thanks for any help!