I'm trying to merge datasets of city council shapefiles with census blocks. I want to be able to see all of the census blocks that lie within each city council district.

I've tried bind and combine, but the resulting attribute table has NA values for most rows.

I want the resulting attribute table to look like:

 CC District 1 -x, -y block 101 CC District 1 -x+1,-y-1 block 102 CC District 1 -x-1,-y+1 block 103 CC District 2 -x-2, -y+1 block 104 etc 

Here is my code:

library(sf) library(leaflet) library(raster) library(tidyr) library(foreign) nycc21 <- sf::read_sf('nycc.shp') %>% sf::st_transform('+proj=longlat +datum=WGS84') nycb20 <- sf::read_sf('nycb2020.shp') %>% sf::st_transform('+proj=longlat +datum=WGS84') merged <- merge(nycc21, nycb20) View(merged) 

enter image description here

You can download reference data here

 
6

Related questions 1 Using R to merge two datasets 6 ggplot2: Combine shapefiles from two different geodatasets 0 How to match/merge data from two different files in R? Related questions 1 Using R to merge two datasets 6 ggplot2: Combine shapefiles from two different geodatasets 0 How to match/merge data from two different files in R? 1 Error when combining shapefiles 5 Merging Two SpatialPolygonsDataFrame Objects 0 Merging two datasets in R 2 Merging two shapefiles in R 2 R Merging Map ShapeFiles Together 1 Merge a dataframe with longitude and latitude and a shape file 1 How to merge spatial data from two multi-polygon layers with identical geography, but different ID's? Load 7 more related questions Show fewer related questions

Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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.