I want to combine voter precinct data with school zone data. Precinct boundaries do not line up neatly with school zone boundaries in all cases.
Code look something like this:
library(rgdal)
library(tigris)
library(sf)
precincts <- readOGR(
dsn = "input/SOEShapefiles2020/SOEShapefiles2020.shp",
layer = "SOEShapefiles2020"
)
precinctDemos <- read.csv("input/data/Party registration in voting precincts.csv")
mPrecDemo <- geo_join(
spatial_data = precincts,
data_frame = precinctDemos,
by_sp = "PRECINCT",
by_df = "Precinct",
how = "inner"
)
elemZones <- readOGR(
dsn = "input/2020-21_Attendance_Boundaries/2020-21_ElemAttendance.shp",
layer = "2020-21_ElemAttendance"
)
elemZones$MSID_ELEM <- as.numeric(elemZones$MSID_ELEM)
attendance <- read.csv("elementary school attendance.csv")
mElem <- geo_join(
spatial_data = elemZones,
data_frame = attendance,
by_sp = "MSID_ELEM",
by_df = "School.",
how = "inner"
)
So mElem
and mPrecDemo
are each "Large SpatialPolygonsDataFrame" objects. How do I perform a spatial join to bring the two objects together? I want to be able to estimate the number of voters in each school zone.