forked from cambiotraining/r-intermediate
-
Notifications
You must be signed in to change notification settings - Fork 28
/
3.workflows-exercises.Rmd
44 lines (29 loc) · 1.03 KB
/
3.workflows-exercises.Rmd
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
---
title: "Exercise: workflows, filtering and sorting"
author: "Mark Dunning and Matt Eldridge"
date: '`r format(Sys.time(), "Last modified: %d %b %Y")`'
output: html_document
---
## Part I -- Workflows using pipes
1. Read in the patients dataset and rewrite the following cleaning steps as a workflow using the `%>%` operator.
```{r eval = FALSE}
library(tidyverse)
patients <- read_tsv("patient-data.txt")
patients <- mutate(patients, Smokes = Smokes %in% c("TRUE", "Yes"))
patients <- mutate(patients, Height = as.numeric(str_remove(Height, pattern = "cm$")))
patients <- mutate(patients, Weight = as.numeric(str_remove(Weight, pattern = "kg$")))
patients <- mutate(patients, BMI = Weight / (Height / 100) ** 2)
patients <- mutate(patients, Overweight = BMI > 25)
```
```{r}
```
2. Add a step to the workflow to round the Height, Weight and BMI to 1 decimal place.
```{r}
```
## Part II - Filtering rows
3. Filter for female patients from New York or New Jersey.
```{r}
```
4. Filter for overweight smokers that are still alive.
```{r}
```