-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTyson wastewater cleaning and analysis_SEW.R
79 lines (58 loc) · 2.4 KB
/
Tyson wastewater cleaning and analysis_SEW.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Author Stacy Woods
# For UCS investigation into total wastewater by Tysons meat processing plants, 2018 - 2022
# Data Source: https://echo.epa.gov/trends/loading-tool/water-pollution-search
# Downloaded 04182024
###Search Type: Discharge Monitoring Report
###Year: 2018 to 2022 (separately)
###Location: Nationwide
###Community: All communities
###Pollutant: Without calculated loadings: Wastewater Flow (selected)
###Industry: All Point Sources
###Facility Name: “Tyson”, “Hillshire Brands”, “Tecumseh Poultry” (separately)
# packages
library(tidyverse)
library(dplyr)
#read in all cvs's in folder
setwd("...")
getwd()
# bring in all csv's # List all CSV files in the directory
file_list <- list.files(pattern = "*.csv")
# Read all CSV files into a list of data frames, skipping the first three rows
df_list <- file_list %>%
map(~ read_csv(., skip = 3))
# Assign each data frame from the list to a separate variable in the environment
df_list %>%
set_names(file_list) %>%
walk2(names(.), ~ assign(.y, .x, envir = .GlobalEnv))
print(head(HillshireBrands2018.csv, 10))
# Combine all data frames into one, appending by rows
combined_df <- df_list %>%
reduce(bind_rows)
# Assign the combined data frame to a variable in the environment
assign("combined_df", combined_df, envir = .GlobalEnv)
########################## Clean data ###########################
# remove entries that are not tyson or subsidiary processing plants
colnames(combined_df)
unique(combined_df$`Facility Name`)
# Identify the rows to keep based on "Facility Name"
rows_to_keep <- which(!(combined_df$`Facility Name` %in% c(
"MCGEE-TYSON AIRPORT",
"CITY OF ARCADIA - WILLIAM TYSON WWTP",
"TYSON MHP",
"TYSONS CENTRAL OFFICE BUILDING A",
"TYSONS TREE WOOD RECYCLERS",
"GRANT COUNTY MULCH, INC-- TYSON'S",
"SCHUSTER CONCRETE READY MIX - SCOTTS RUN/TYSONS",
"BROWN TYSON RESIDENCE"
)))
# Filter the data frame to keep only the rows identified
mydata <- combined_df[rows_to_keep, ]
# Assign the filtered data frame to a variable in the environment
assign("mydata", mydata, envir = .GlobalEnv)
colnames(mydata)
unique(mydata$`Facility Name`)
################### Calculate total wastewater ###################
str(mydata$`Total Annual Flow (MMGal)`)
sum(mydata$`Total Annual Flow (MMGal)`, na.rm = TRUE)
# = 87037.29 MMGal = 87.03729 billion gall
# END #