-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyserivers.Rmd
More file actions
42 lines (29 loc) · 1.08 KB
/
analyserivers.Rmd
File metadata and controls
42 lines (29 loc) · 1.08 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
26
27
28
29
30
31
32
33
34
35
36
37
---
title: "Combine rivers CSVs"
output: html_notebook
---
# Analyse rivers data
In another notebook we fetched and combined multiple CSVs. The results of that can be imported in the line below:
```{r readrds}
combineddata<- readRDS("combineddata.rds")
```
## Narrow the scope
```{r filter}
riversonly <- dplyr::filter(combineddata, Water.body.type == "River")
riversonly <- dplyr::filter(riversonly, Activity != "Not applicable")
riversonly <- dplyr::filter(riversonly, Activity != "Other (not in list, must add details in comments)")
```
## Add unique identifier
```{r create new cols}
#Combine body id and year
riversonly$riveryearid <- paste(riversonly$Water.body.id, riversonly$Classification.Year, sep="-")
#Does the Activity column contain 'sewage'
riversonly$sewage <- grepl(".*ewage.*", riversonly$Activity)
```
```{r sql}
riveranalysis <- sqldf::sqldf("SELECT count(riveryearid) as rivers, sewage, `Classification.Year`
FROM riversonly
GROUP BY `Classification.Year`, sewage
ORDER BY `Classification.Year`, sewage desc
LIMIT 10")
```