I'd like to create polygons with st_voronoi and merge them by a variable
library(sf)
nc_centroids <- st_transform(nc_centroids,crs=32119)
nc_centroids$foo <- c(rep("green",50),rep("red",50))
nc <- st_transform(nc,crs=32119)
v <- st_voronoi(st_union(nc_centroids))
plot(v, col = 0)
plot(st_intersection(st_cast(v), st_union(nc)), col = 0)
plot(nc_centroids, add = TRUE)
How might I merge the polygons in v by nc_centroids$foo to create two big polygons? I can think of some hacks, like using lapply to join the individual polygons of v, e.g., (v[[1]][[x]]). But surely there's something easier
