Skip to content

Commit

Permalink
Subset restoration data for oyster projects
Browse files Browse the repository at this point in the history
  • Loading branch information
kflahertywalia committed Jan 7, 2025
1 parent 668d986 commit b3b3bad
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
61 changes: 61 additions & 0 deletions R/oyster_projects.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
library(tidyverse)
library(here)
library(dplyr)

# search all restoration projects --------------------------------------------------

# from https://github.com/tbep-tech/TBEP_Habitat_Restoration
pth <- 'https://raw.githubusercontent.com/tbep-tech/TBEP_Habitat_Restoration/main/restoration.csv'

rstdata <- read.csv(pth, stringsAsFactors = F)%>%
mutate(Year = Federal_Fiscal_Year,
Partner = Lead_Implementer,
Lat = Latitude,
Lon = Longitude,
Restoration_Technique,
Primary = PrimaryHabitat,
General = GeneralHabitat,
Activity = GeneralActivity,
Miles = case_when(
Activity %in% 'Maintenance' & Restoration_Technique %in% 'Debris Removal' ~ NA_real_,
T ~ Miles
),
Acres = as.numeric(Acres),
Miles = case_when(
is.na(Miles) & !is.na(Feet) ~ Feet / 5280,
T ~ Miles
),
General = case_when(
General == 'estuarine' ~ 'Estuarine',
grepl('^Upland', General) ~ 'Uplands',
grepl('^Mix|^Other', General) ~ 'Mixed',
T ~ General
),
General = ifelse(General == '', NA, General),
Primary = ifelse(Primary == '', NA, Primary),
Activity = ifelse(Activity == '', NA, Activity)
)


# Check for "oyster" in any column-----------------------------------------------
result <- apply(rstdata, 2, function(x) grepl(c("oyster","Oyster"), x, ignore.case = TRUE))
# Find the rows containing "oyster" in any column
rows_with_oyster <- which(rowSums(result) > 0)
# Display the rows where "oyster" appears
oyster <- rstdata[rows_with_oyster, ]%>%
filter(General %in% c("Estuarine","Mix (estuarine and freshwater)"), Activity=="Restoration")

#filter by PrimaryHabitat (for years >=2006)------------------------------------
oyster2 <- rstdata[rows_with_oyster, ]%>%
filter(Primary %in% c("Oyster Bars","Hard Bottom","Mangrove Forests","Living Shorelines","Artificial Reefs",
"Low-Salinity Salt Marsh", "Intertidal Estuarine (Other)"), Activity=='Restoration')

#combine dataframes and delete duplicates---------------------------------------------------
oyster_merge <- rbind(oyster, oyster2)
oyster_all <- distinct(oyster_merge)%>%
select(Year, Partner, Lat, Lon, Project_Name, Project_Description, Habitat_Type,
Restoration_Technique, Project_Benefits, Primary, General, Activity, Acres, Miles)


save(oyster_all, file = here('data/subsets/oysterprojects.RData'))
write.csv(oyster_all, here("data/subsets/oysterprojects.csv"), row.names = FALSE)
Binary file added data/subsets/oysterprojects.RData
Binary file not shown.
Loading

0 comments on commit b3b3bad

Please sign in to comment.