-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiltering_data.R
More file actions
33 lines (22 loc) · 1.1 KB
/
filtering_data.R
File metadata and controls
33 lines (22 loc) · 1.1 KB
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
### FILTERING AND CLEANING DATA FOR THE CODYN TUTORIAL
data <- read_csv("Data/TLW_invertebrateDensity.csv") %>%
pivot_longer( "Aeshna":"Trichoptera", names_to = "species", values_to = "density") %>%
mutate(abundance = density * 0.33,
treatment = case_when(catchment %in% c("33") ~ "low",
catchment %in% c("34U") ~ "medium",
catchment %in% c("34L") ~ "high",
catchment %in% c("34M") ~ "control",
TRUE ~ "natural"),
date_yr_m = as.yearmon(paste0(year,month), "%Y %b")) %>%
drop_na(abundance) %>%
filter(year >= 1995,
year <= 2001,
# stringr::str_starts(catchment, stringr::fixed("34")),
month %in% c("june", "may"))
# summing over treatments sampling events
data_sum<- data %>%
filter(treatment %in% c("low", "medium", "high", "control")) %>%
group_by(year, species, treatment, replicate) %>%
summarise(abundance = sum(abundance))
# write into csv
write.csv(x=data_sum, file="stream_invertebrates.csv", row.names=FALSE)