ds4owd - data science for openwashdata
ETH Zurich
Oct 23, 2025
In discussion groups of 3, share your examples and discuss how the recommendations would improve your workflows.
10:00
use
avoid
variable_name | description |
---|---|
ts | Total solids in g/L. |
users | Number of users per system. |
system | Sanitation system in use at sample location (septic tank / pit latrine). |
mutate()
& case_when()
mutate()
adds new variables to a data framecase_when()
is another form of an if-else statementSit back and enjoy!
20:00
Please get up and move! Let your emails rest in peace.
10:00
Image generated with DALL-E 3 by OpenAI
md-05a-conditions-your-turn.qmd
file and click on it to open it in the top left window.20:00
mutate()
and case_when()
to change the ts value of 0.72 to 8.72.id | date | system | location | users | ts |
---|---|---|---|---|---|
1 | 2023-11-01 | pit latrine | household | 5 | 136.24 |
2 | 2023-11-01 | pit latrine | household | 7 | 102.45 |
3 | 2023-11-01 | pit latrine | household | NA | 57.02 |
4 | 2023-11-01 | pit latrine | household | 6 | 27.03 |
5 | 2023-11-01 | pit latrine | household | 12 | 97.27 |
6 | 2023-11-02 | pit latrine | household | 7 | 78.21 |
7 | 2023-11-02 | septic tank | household | 14 | 15.24 |
8 | 2023-11-02 | septic tank | household | 4 | 29.39 |
9 | 2023-11-02 | septic tank | household | 10 | 64.22 |
10 | 2023-11-02 | septic tank | household | 12 | 8.01 |
11 | 2023-11-03 | pit latrine | public toilet | 50 | 11.24 |
12 | 2023-11-03 | pit latrine | public toilet | 32 | 84.05 |
13 | 2023-11-03 | pit latrine | public toilet | 41 | 55.92 |
14 | 2023-11-03 | pit latrine | public toilet | 160 | 15.32 |
15 | 2023-11-03 | pit latrine | public toilet | 20 | 22.65 |
16 | 2023-11-04 | septic tank | public toilet | 26 | 8.72 |
17 | 2023-11-04 | septic tank | public toilet | 91 | 43.92 |
18 | 2023-11-04 | septic tank | public toilet | 68 | 10.37 |
19 | 2023-11-04 | septic tank | public toilet | 112 | 23.21 |
20 | 2023-11-04 | septic tank | public toilet | 59 | 15.64 |
mutate()
and case_when()
to change the system value of id 6 from “pit latrine” to “septic tank”.id | date | system | location | users | ts |
---|---|---|---|---|---|
1 | 2023-11-01 | pit latrine | household | 5 | 136.24 |
2 | 2023-11-01 | pit latrine | household | 7 | 102.45 |
3 | 2023-11-01 | pit latrine | household | NA | 57.02 |
4 | 2023-11-01 | pit latrine | household | 6 | 27.03 |
5 | 2023-11-01 | pit latrine | household | 12 | 97.27 |
6 | 2023-11-02 | septic tank | household | 7 | 78.21 |
7 | 2023-11-02 | septic tank | household | 14 | 15.24 |
8 | 2023-11-02 | septic tank | household | 4 | 29.39 |
9 | 2023-11-02 | septic tank | household | 10 | 64.22 |
10 | 2023-11-02 | septic tank | household | 12 | 8.01 |
11 | 2023-11-03 | pit latrine | public toilet | 50 | 11.24 |
12 | 2023-11-03 | pit latrine | public toilet | 32 | 84.05 |
13 | 2023-11-03 | pit latrine | public toilet | 41 | 55.92 |
14 | 2023-11-03 | pit latrine | public toilet | 160 | 15.32 |
15 | 2023-11-03 | pit latrine | public toilet | 20 | 22.65 |
16 | 2023-11-04 | septic tank | public toilet | 26 | 0.72 |
17 | 2023-11-04 | septic tank | public toilet | 91 | 43.92 |
18 | 2023-11-04 | septic tank | public toilet | 68 | 10.37 |
19 | 2023-11-04 | septic tank | public toilet | 112 | 23.21 |
20 | 2023-11-04 | septic tank | public toilet | 59 | 15.64 |
ts_cat
to the dataframe. that categorises sludge samples into low, medium and high solids content.Use mutate()
and case_when()
to create the new variable.id | date | system | location | users | ts | ts_cat |
---|---|---|---|---|---|---|
1 | 2023-11-01 | pit latrine | household | 5 | 136.24 | high |
2 | 2023-11-01 | pit latrine | household | 7 | 102.45 | high |
3 | 2023-11-01 | pit latrine | household | NA | 57.02 | high |
4 | 2023-11-01 | pit latrine | household | 6 | 27.03 | medium |
5 | 2023-11-01 | pit latrine | household | 12 | 97.27 | high |
6 | 2023-11-02 | pit latrine | household | 7 | 78.21 | high |
7 | 2023-11-02 | septic tank | household | 14 | 15.24 | medium |
8 | 2023-11-02 | septic tank | household | 4 | 29.39 | medium |
9 | 2023-11-02 | septic tank | household | 10 | 64.22 | high |
10 | 2023-11-02 | septic tank | household | 12 | 8.01 | low |
11 | 2023-11-03 | pit latrine | public toilet | 50 | 11.24 | low |
12 | 2023-11-03 | pit latrine | public toilet | 32 | 84.05 | high |
13 | 2023-11-03 | pit latrine | public toilet | 41 | 55.92 | high |
14 | 2023-11-03 | pit latrine | public toilet | 160 | 15.32 | medium |
15 | 2023-11-03 | pit latrine | public toilet | 20 | 22.65 | medium |
16 | 2023-11-04 | septic tank | public toilet | 26 | 0.72 | low |
17 | 2023-11-04 | septic tank | public toilet | 91 | 43.92 | medium |
18 | 2023-11-04 | septic tank | public toilet | 68 | 10.37 | low |
19 | 2023-11-04 | septic tank | public toilet | 112 | 23.21 | medium |
20 | 2023-11-04 | septic tank | public toilet | 59 | 15.64 | medium |
ts_cat | n |
---|---|
high | 8 |
low | 4 |
medium | 8 |
Sit back and enjoy!
15:00
Please get up and move! Let your emails rest in peace.
10:00
Image generated with DALL-E 3 by OpenAI
gt
package is one of the most popular and flexiblekable()
function of knitr
package useful for simple tablesmd-03c-tables.qmd
file and click on it to open it in the top left window.30:00
Help readers to navigate your document with numbered references and hyperlinks to entities like figures and tables.
Cross referencing steps:
fig-
or tbl-
.@fig-...
or @tbl-...
.The presence of the caption (A few penguins
) and label (#tbl-penguins
) make this table referenceable:
See @tbl-penguins
for data on a few penguins.
becomes:
See Table 1 for data on a few penguins.
species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | year |
---|---|---|---|---|---|---|---|
Adelie | Torgersen | 39.1 | 18.7 | 181 | 3750 | male | 2007 |
Adelie | Torgersen | 39.5 | 17.4 | 186 | 3800 | female | 2007 |
Adelie | Torgersen | 40.3 | 18.0 | 195 | 3250 | female | 2007 |
Adelie | Torgersen | NA | NA | NA | NA | NA | 2007 |
Adelie | Torgersen | 36.7 | 19.3 | 193 | 3450 | female | 2007 |
Adelie | Torgersen | 39.3 | 20.6 | 190 | 3650 | male | 2007 |
Slides created via revealjs and Quarto: https://quarto.org/docs/presentations/revealjs/ Access slides as PDF on GitHub
All material is licensed under Creative Commons Attribution Share Alike 4.0 International.