Suppose I had voting data from the 2016 election at voting district level, and population data (from 2010 Census, say) at the block or tract level. I am hoping there are no blocks/tracts in two districts. So assume that all we have to do is amalgamate up with no boundary issues. The data are in shapefiles.

What's the easiest way to use R to compare the polygons representing blocks/tracts with voting districts and then just sum the population of all the blocks/tracts within a voting district to calculate the total population of that district?

EDIT: I have found that this is very easy in ArcGIS using the join functionality, so I will just use that.

1 Answer 1


While you have found a solution in Arc, in the spirit of your question we can offer an R, specifically simple features and dplyr approach.

#bring in packages, assuming you have your data already

tract_vars <- st_read("path_tract_shape")
voting_district <- st_read("path_to_voting_district")

#we'll keep st_intersects as the rule assuming tracts neatly nest w/in districts
voting_tracts <- st_join(voting_district, tract_vars, join = st_intersects)

#sum up population
voting_pop <- voting_tracts %>% group_by(voting_district_id) %>%
summarize(district_pop = sum(population_from_tracts))

Note this probably follows the basic steps you would've made in Arc, but this sf approach, if all you need is population sum will be faster and more easy to troubleshoot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.