library(terra)
library(ggplot2)
v <- vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
# Grouped
gr_v <- v %>%
mutate(start_with_s = substr(name, 1, 1) == "S") %>%
group_by(start_with_s)
# Dissolving
diss <- gr_v %>%
summarise(n = dplyr::n(), mean = mean(as.double(cpro)))
diss
autoplot(diss, aes(fill = start_with_s)) + ggplot2::ggtitle("Dissolved")
# Not dissolving
no_diss <- gr_v %>%
summarise(n = dplyr::n(), mean = mean(as.double(cpro)), .dissolve = FALSE)
# Same statistic
no_diss
autoplot(no_diss, aes(fill = start_with_s)) +
ggplot2::ggtitle("Not Dissolved")
Run the code above in your browser using DataLab