task 1:

Set up a R project for the R-Spatial section.

setwd("~/Data Analysis and Viz/Week7/Data/R-Spatial_I_Lab")
nyc_zips <- st_read("C:/Users/Zack/Documents/Data Analysis and Viz/Week7/Data/R-Spatial_I_Lab/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source 
##   `C:\Users\Zack\Documents\Data Analysis and Viz\Week7\Data\R-Spatial_I_Lab\ZIP_CODE_040114.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 263 features and 12 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: 913129 ymin: 120020.9 xmax: 1067494 ymax: 272710.9
## Projected CRS: NAD83 / New York Long Island (ftUS)
summary(nyc_zips)
##    ZIPCODE            BLDGZIP            PO_NAME            POPULATION      
##  Length:263         Length:263         Length:263         Min.   :     0.0  
##  Class :character   Class :character   Class :character   1st Qu.:    49.5  
##  Mode  :character   Mode  :character   Mode  :character   Median : 27985.0  
##                                                           Mean   : 31933.9  
##                                                           3rd Qu.: 54445.0  
##                                                           Max.   :109069.0  
##       AREA              STATE              COUNTY            ST_FIPS         
##  Min.   :     3155   Length:263         Length:263         Length:263        
##  1st Qu.:   964323   Class :character   Class :character   Class :character  
##  Median : 21927545   Mode  :character   Mode  :character   Mode  :character  
##  Mean   : 31816554                                                           
##  3rd Qu.: 45935567                                                           
##  Max.   :473985727                                                           
##    CTY_FIPS             URL              SHAPE_AREA   SHAPE_LEN
##  Length:263         Length:263         Min.   :0    Min.   :0  
##  Class :character   Class :character   1st Qu.:0    1st Qu.:0  
##  Mode  :character   Mode  :character   Median :0    Median :0  
##                                        Mean   :0    Mean   :0  
##                                        3rd Qu.:0    3rd Qu.:0  
##                                        Max.   :0    Max.   :0  
##           geometry  
##  POLYGON      :263  
##  epsg:2263    :  0  
##  +proj=lcc ...:  0  
##                     
##                     
## 

task 2:

Task 2: Read Health Facilities and Convert to sf

health_data <- read_csv("C:/Users/Zack/Documents/Data Analysis and Viz/Week7/Data/R-Spatial_I_Lab/NYS_Health_Facility.csv")

# Convert to sf object
health_sf <- health_data %>%
  filter(!is.na(`Facility Longitude`), !is.na(`Facility Latitude`)) %>%
  st_as_sf(coords = c("Facility Longitude", "Facility Latitude"), crs = 4326)

mapview::mapview(health_sf)

task 3:

Task 3: Read Retail Food Stores

retail_data <- read_csv("C:/Users/Zack/Documents/Data Analysis and Viz/Week7/Data/R-Spatial_I_Lab/nys_retail_food_store_xy.csv", locale = locale(encoding = "Latin1"))

task 4:

Task 4: Filter NYC Stores and Convert to sf

nyc_retail_data <- retail_data %>%
  filter(`ï..County` %in% c("Bronx", "Kings", "New York", "Queens", "Richmond")) %>%
  filter(!is.na(X), !is.na(Y))

nyc_retail_sf <- nyc_retail_data %>%
  st_as_sf(coords = c("X", "Y"), crs = 4326)

mapview(nyc_retail_sf)

task 5:

Task 5: Save as RData

save(nyc_zips, health_sf, nyc_retail_sf, file = "nyc_spatial_data.RData")