Author

Naomi Thornhill

Published

March 22, 2025

Explanation of the template

Update the title with your information. Make sure to include identification information so that we know it is your submission.

Also update the author name and date accordingly.

Check out the Source Code from the top-right corner </>Code menu.

In the following R code chunk, load_packages is the code chunk name. include=FALSE suggests that the code chunk will run, but the code itself and its outputs will not be included in the rendered HTML. echo=TRUE in the following code chunk suggests that the code and results from running the code will be included in the rendered HTML.

R Spatial Lab Assignment # 1

Don’t use a single chunk for the entire assignment. Break it into multiple chunks.

task 1:

Read CSC file on the drive.

Code
NYS_Retail_Food_Stores <- read_csv("R-Spatial Labs/Lab 7/NYS_Retail_Food_Stores.csv")
Rows: 29389 Columns: 15
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (11): County, License Number, Operation Type, Establishment Type, Entity...
dbl  (1): Zip Code
num  (1): Square Footage
lgl  (2): Address Line 2, Address Line 3

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Extract Coordinates from Location

Code
colnames(NYS_Retail_Food_Stores)
 [1] "County"             "License Number"     "Operation Type"    
 [4] "Establishment Type" "Entity Name"        "DBA Name"          
 [7] "Street Number"      "Street Name"        "Address Line 2"    
[10] "Address Line 3"     "City"               "State"             
[13] "Zip Code"           "Square Footage"     "Location"          
Code
leftPos <- stringr::str_locate(NYS_Retail_Food_Stores$Location, "\\(")[,1]
rghtPos <- stringr::str_locate(NYS_Retail_Food_Stores$Location, "\\)")[,1]
NYS_Retail_Food_Stores$Coords <- stringr::str_sub(NYS_Retail_Food_Stores$Location, leftPos + 1, rghtPos - 1)

Name the coordinates

Code
cmmaPos <- stringr::str_locate(NYS_Retail_Food_Stores$Coords, ", ")
NYS_Retail_Food_Stores$Y <- as.numeric(stringr::str_sub(NYS_Retail_Food_Stores$Coords, 1, cmmaPos[,1] - 1))
Warning: NAs introduced by coercion
Code
NYS_Retail_Food_Stores$X <- as.numeric(stringr::str_sub(NYS_Retail_Food_Stores$Coords, cmmaPos[,2] + 1))
Warning: NAs introduced by coercion
Code
NYS_Retail_Food_Stores <- tidyr::drop_na(NYS_Retail_Food_Stores, X, Y)

Make a sf object

Code
nysFoodStoreSF <- st_as_sf(NYS_Retail_Food_Stores, coords = c('X', 'Y'))