R Spatial Lab Assignment # 1

Task 0 Setting Up Lab:

To set up for the lab, I changed my working directory to where I stored the folder setwd(“C:/Users/Max/Desktop/Section_07/R-Spatial_I_Lab”)

Task 1 Reading Data Files:

nycZipSf<-st_read("ZIP_CODE_040114/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source 
##   `C:\Users\Max\Desktop\Section_07\R-Spatial_I_Lab\ZIP_CODE_040114\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)

Task 2 Health Facility Data:

#this reads in the csv file of the health facility
nysHealth<-read.csv("NYS_Health_Facility.csv")

#removes the missing values and cleans up data
nysHealthNoMissingVals <- subset(nysHealth, !is.na(Facility.Longitude) & !is.na(Facility.Latitude))

#converts dataframe from last step into a sf
nysHealthSf<-st_as_sf(nysHealthNoMissingVals, coords = c("Facility.Longitude", "Facility.Latitude"), crs = 4326) #added the use of crs since it was defined as the EPSG code in the lab assignment
str(nysHealthSf)
## Classes 'sf' and 'data.frame':   3848 obs. of  35 variables:
##  $ Facility.ID                 : int  204 620 1156 2589 3455 3853 4249 4473 6230 6482 ...
##  $ Facility.Name               : chr  "Hospice at Lourdes" "Charles T Sitrin Health Care Center Inc" "East Side Nursing Home" "Wellsville Manor Care Center" ...
##  $ Short.Description           : chr  "HSPC" "NH" "NH" "NH" ...
##  $ Description                 : chr  "Hospice" "Residential Health Care Facility - SNF" "Residential Health Care Facility - SNF" "Residential Health Care Facility - SNF" ...
##  $ Facility.Open.Date          : chr  "06/01/1985" "02/01/1989" "08/01/1979" "02/01/1989" ...
##  $ Facility.Address.1          : chr  "4102 Old Vestal Road" "2050 Tilden Avenue" "62 Prospect St" "4192A Bolivar Road" ...
##  $ Facility.Address.2          : chr  "" "" "" "" ...
##  $ Facility.City               : chr  "Vestal" "New Hartford" "Warsaw" "Wellsville" ...
##  $ Facility.State              : chr  "New York" "New York" "New York" "New York" ...
##  $ Facility.Zip.Code           : chr  "13850" "13413" "14569" "14895" ...
##  $ Facility.Phone.Number       : num  6.08e+09 3.16e+09 5.86e+09 5.86e+09 7.17e+09 ...
##  $ Facility.Fax.Number         : num  NA NA NA NA NA ...
##  $ Facility.Website            : chr  "" "" "" "" ...
##  $ Facility.County.Code        : int  3 32 60 2 14 29 14 29 7093 29 ...
##  $ Facility.County             : chr  "Broome" "Oneida" "Wyoming" "Allegany" ...
##  $ Regional.Office.ID          : int  3 3 1 1 1 7 1 7 5 7 ...
##  $ Regional.Office             : chr  "Central New York Regional Office" "Central New York Regional Office" "Western Regional Office - Buffalo" "Western Regional Office - Buffalo" ...
##  $ Main.Site.Name              : chr  "" "" "" "" ...
##  $ Main.Site.Facility.ID       : int  NA NA NA NA NA NA NA NA 1463 NA ...
##  $ Operating.Certificate.Number: chr  "0301501F" "3227304N" "6027303N" "0228305N" ...
##  $ Operator.Name               : chr  "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  "169 Riverside Drive" "Box 1000 Tilden Avenue" "62 Prospect Street" "4192a Bolivar Road" ...
##  $ Operator.Address.2          : chr  "" "" "" "" ...
##  $ Operator.City               : chr  "Binghamton" "New Hartford" "Warsaw" "Wellsville" ...
##  $ Operator.State              : chr  "New York" "New York" "New York" "New York" ...
##  $ Operator.Zip.Code           : chr  "13905" "13413" "14569" "14897" ...
##  $ Cooperator.Name             : chr  "" "" "" "" ...
##  $ Cooperator.Address          : chr  "" "" "" "" ...
##  $ Cooperator.Address.2        : chr  "" "" "" "" ...
##  $ Cooperator.City             : chr  "" "" "" "" ...
##  $ Cooperator.State            : chr  "New York" "New York" "New York" "New York" ...
##  $ Cooperator.Zip.Code         : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ Ownership.Type              : chr  "Not for Profit Corporation" "Not for Profit Corporation" "Business Corporation" "LLC" ...
##  $ Facility.Location           : chr  "(42.097095, -75.975243)" "(43.05497, -75.228828)" "(42.738979, -78.12867)" "(42.126461, -77.967834)" ...
##  $ geometry                    :sfc_POINT of length 3848; first list element:  'XY' num  -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" ...

Task 3 Retail Food Store Data:

#this reads in the csv file of the food retail stores
nysFood<-read_csv("nys_retail_food_store_xy.csv",show_col_types = F)

#removes rows missing coordinates
nysFoodNoMissingVals <- subset(nysFood, !is.na(X) & !is.na(Y))

#converts dataframe from last step into a sf
nysFoodSf<-st_as_sf(nysFoodNoMissingVals, coords = c("X", "Y"), crs = 4326)#added the use of crs since it was defined as the EPSG code in the lab assignment

Task 4 Mapping Data:

#this maps the NYC postal areas in pink
mapview(nycZipSf, col.regions = "pink", popup = NULL) #not having popup null caused my file not to render
#this maps the NYS health facilities in green
mapview(nysHealthSf, col.regions = "green", popup = NULL) #shows regions in antarctica and africa even though I made sure to filter data and reduce it to the crs given
#this maps the NYS retail food stores in blue
mapview(nysFoodSf, col.regions = "blue", popup = NULL) 

Task 5 Saving Data:

save(nycZipSf, nysHealthSf, nysFoodSf, file = "Week7_Spatial_Data.RData")