I loaded the three sf objects saved in Week 7, including ZIP code polygons, health facilities, and retail food stores. These saved objects are required for the Week 8 assignment.
Output:
# load week 7 sf objectsload("data/R-Spatial_II_Lab/week7_spatial_objects.RData")# inspect the loaded objectsstr(nyc_zip_sf)
Classes 'sf' and 'data.frame': 263 obs. of 13 variables:
$ ZIPCODE : chr "11436" "11213" "11212" "11225" ...
$ BLDGZIP : chr "0" "0" "0" "0" ...
$ PO_NAME : chr "Jamaica" "Brooklyn" "Brooklyn" "Brooklyn" ...
$ POPULATION: num 18681 62426 83866 56527 72280 ...
$ AREA : num 22699295 29631004 41972104 23698630 36868799 ...
$ STATE : chr "NY" "NY" "NY" "NY" ...
$ COUNTY : chr "Queens" "Kings" "Kings" "Kings" ...
$ ST_FIPS : chr "36" "36" "36" "36" ...
$ CTY_FIPS : chr "081" "047" "047" "047" ...
$ URL : chr "http://www.usps.com/" "http://www.usps.com/" "http://www.usps.com/" "http://www.usps.com/" ...
$ SHAPE_AREA: num 0 0 0 0 0 0 0 0 0 0 ...
$ SHAPE_LEN : num 0 0 0 0 0 0 0 0 0 0 ...
$ geometry :sfc_POLYGON of length 263; first list element: List of 1
..$ : num [1:159, 1:2] 1038098 1038142 1038171 1038280 1038521 ...
..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
..- attr(*, "names")= chr [1:12] "ZIPCODE" "BLDGZIP" "PO_NAME" "POPULATION" ...
str(health_fac_sf)
sf [3,843 × 35] (S3: sf/tbl_df/tbl/data.frame)
$ Facility ID : num [1:3843] 204 620 1156 2589 3455 ...
$ Facility Name : chr [1:3843] "Hospice at Lourdes" "Charles T Sitrin Health Care Center Inc" "East Side Nursing Home" "Wellsville Manor Care Center" ...
$ Short Description : chr [1:3843] "HSPC" "NH" "NH" "NH" ...
$ Description : chr [1:3843] "Hospice" "Residential Health Care Facility - SNF" "Residential Health Care Facility - SNF" "Residential Health Care Facility - SNF" ...
$ Facility Open Date : chr [1:3843] "06/01/1985" "02/01/1989" "08/01/1979" "02/01/1989" ...
$ Facility Address 1 : chr [1:3843] "4102 Old Vestal Road" "2050 Tilden Avenue" "62 Prospect St" "4192A Bolivar Road" ...
$ Facility Address 2 : chr [1:3843] NA NA NA NA ...
$ Facility City : chr [1:3843] "Vestal" "New Hartford" "Warsaw" "Wellsville" ...
$ Facility State : chr [1:3843] "New York" "New York" "New York" "New York" ...
$ Facility Zip Code : chr [1:3843] "13850" "13413" "14569" "14895" ...
$ Facility Phone Number : num [1:3843] 6.08e+09 3.16e+09 5.86e+09 5.86e+09 7.17e+09 ...
$ Facility Fax Number : num [1:3843] NA NA NA NA NA ...
$ Facility Website : chr [1:3843] NA NA NA NA ...
$ Facility County Code : num [1:3843] 3 32 60 2 14 ...
$ Facility County : chr [1:3843] "Broome" "Oneida" "Wyoming" "Allegany" ...
$ Regional Office ID : num [1:3843] 3 3 1 1 1 7 1 7 5 7 ...
$ Regional Office : chr [1:3843] "Central New York Regional Office" "Central New York Regional Office" "Western Regional Office - Buffalo" "Western Regional Office - Buffalo" ...
$ Main Site Name : chr [1:3843] NA NA NA NA ...
$ Main Site Facility ID : num [1:3843] NA NA NA NA NA ...
$ Operating Certificate Number: chr [1:3843] "0301501F" "3227304N" "6027303N" "0228305N" ...
$ Operator Name : chr [1:3843] "Our Lady of Lourdes Memorial Hospital Inc" "Charles T Sitrin Health Care Center, Inc" "East Side Nursing Home Inc" "Wellsville Manor LLC" ...
$ Operator Address 1 : chr [1:3843] "169 Riverside Drive" "Box 1000 Tilden Avenue" "62 Prospect Street" "4192a Bolivar Road" ...
$ Operator Address 2 : chr [1:3843] NA NA NA NA ...
$ Operator City : chr [1:3843] "Binghamton" "New Hartford" "Warsaw" "Wellsville" ...
$ Operator State : chr [1:3843] "New York" "New York" "New York" "New York" ...
$ Operator Zip Code : chr [1:3843] "13905" "13413" "14569" "14897" ...
$ Cooperator Name : chr [1:3843] NA NA NA NA ...
$ Cooperator Address : chr [1:3843] NA NA NA NA ...
$ Cooperator Address 2 : chr [1:3843] NA NA NA NA ...
$ Cooperator City : chr [1:3843] NA NA NA NA ...
$ Cooperator State : chr [1:3843] "New York" "New York" "New York" "New York" ...
$ Cooperator Zip Code : chr [1:3843] NA NA NA NA ...
$ Ownership Type : chr [1:3843] "Not for Profit Corporation" "Not for Profit Corporation" "Business Corporation" "LLC" ...
$ Facility Location : chr [1:3843] "(42.097095, -75.975243)" "(43.05497, -75.228828)" "(42.738979, -78.12867)" "(42.126461, -77.967834)" ...
$ geometry :sfc_POINT of length 3843; first list element: 'XY' num [1:2] -76 42.1
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
..- attr(*, "names")= chr [1:34] "Facility ID" "Facility Name" "Short Description" "Description" ...
str(retail_food_sf)
sf [11,301 × 17] (S3: sf/tbl_df/tbl/data.frame)
$ County : chr [1:11301] "Bronx" "Bronx" "Bronx" "Bronx" ...
$ License Number : chr [1:11301] "734149" "606221" "606228" "723375" ...
$ Operation Type : chr [1:11301] "Store" "Store" "Store" "Store" ...
$ Establishment Type: chr [1:11301] "JAC" "JAC" "JAC" "JAC" ...
$ Entity Name : chr [1:11301] "7 ELEVEN FOOD STORE #37933H" "1001 SAN MIGUEL FOOD CENTER INC" "1029 FOOD PLAZA INC" "1078 DELI GROCERY CORP" ...
$ DBA Name : chr [1:11301] NA "1001 SAN MIGUEL FD CNTR" "1029 FOOD PLAZA" "1078 DELI GROCERY" ...
$ Street Number : chr [1:11301] "500" "1001" "122" "1078" ...
$ Street Name : chr [1:11301] "BAYCHESTER AVE" "SHERIDAN AVE" "E 181ST ST" "EAST 165TH STREET" ...
$ Address Line 2 : logi [1:11301] NA NA NA NA NA NA ...
$ Address Line 3 : logi [1:11301] NA NA NA NA NA NA ...
$ City : chr [1:11301] "BRONX" "BRONX" "BRONX" "BRONX" ...
$ State : chr [1:11301] "NY" "NY" "NY" "NY" ...
$ Zip Code : num [1:11301] 10475 10456 10453 10459 10456 ...
$ Square Footage : num [1:11301] 0 1100 2000 1200 1500 2400 1000 1200 3400 500 ...
$ Location : chr [1:11301] "500 BAYCHESTER AVE\nBRONX, NY 10475\n(40.869156, -73.831875)" "1001 SHERIDAN AVE\nBRONX, NY 10456\n(40.829061, -73.919613)" "122 E 181ST ST\nBRONX, NY 10453\n(40.854755, -73.902853)" "1078 EAST 165TH STREET\nBRONX, NY 10459\n(40.825105, -73.890589)" ...
$ coords_text : chr [1:11301] "40.869156, -73.831875" "40.829061, -73.919613" "40.854755, -73.902853" "40.825105, -73.890589" ...
$ geometry :sfc_POINT of length 11301; first list element: 'XY' num [1:2] -73.8 40.9
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
..- attr(*, "names")= chr [1:16] "County" "License Number" "Operation Type" "Establishment Type" ...
Task 2: Read and join one COVID by ZCTA dataset
I read one COVID testing dataset by modified ZIP code tabulation area and joined it to the ZIP polygon layer using the ZIP code field.
Output:
# read the chosen COVID datasetcovid_raw <-read_csv("data/R-Spatial_II_Lab/tests-by-zcta_2020_04_19.csv",show_col_types =FALSE)# make join fields the same typenyc_zip_sf <- nyc_zip_sf %>%mutate(ZIPCODE =as.character(ZIPCODE))covid_raw <- covid_raw %>%mutate(MODZCTA =as.character(MODZCTA))# join COVID data to ZIP polygonszip_covid_sf <- nyc_zip_sf %>%left_join(covid_raw, by =c("ZIPCODE"="MODZCTA"))# inspect the joined resultnames(zip_covid_sf)
I joined the COVID data, retail food store counts, nursing home counts, and demographic summaries into one final ZIP-level sf object.
Output:
# combine all ZIP-level informationfinal_zip_sf <- zip_covid_sf %>%left_join(zip_food_count, by ="ZIPCODE") %>%left_join(zip_health_count, by ="ZIPCODE") %>%left_join(zip_demo, by ="ZIPCODE")# inspect final objectnames(final_zip_sf)