I have list of people grouped by their counties and by villages. I would like to count the number of villages in the respective counties. I am able to count the number of people in each county.
library(dplyr)
set.seed(123)
df <- data.frame(
person = 1:100,
county = round(runif(100, 1, 5)),
village = round(runif(100, 1, 10))
)
# Number of people per county
df %>% count(county )