forked from PMacDaSci/r-intro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution-exercise3.Rmd
More file actions
51 lines (35 loc) · 852 Bytes
/
solution-exercise3.Rmd
File metadata and controls
51 lines (35 loc) · 852 Bytes
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
---
title: "Exercise 3"
author: "Mark Dunning"
date: '`r format(Sys.time(), "Last modified: %d %b %Y")`'
output: pdf_document
---
# Reading the data
```{r}
patients <- read.delim("patient-info.txt")
```
# Analysis
```{r}
BMI <- (patients$Weight)/((patients$Height/100)^2)
upper.limit <- mean(BMI,na.rm = TRUE) + 2*sd(BMI,na.rm = TRUE)
```
# Plotting
```{r}
plot(BMI)
# Add a horizonal line:
abline(h=upper.limit)
```
## Write out the results
```{r}
patients$BMI <- round(BMI,1)
candidates <- which(BMI > upper.limit)
write.csv(patients[candidates,], file="selectedSamples.csv")
```
# Exercise
```{r}
lower.limit <- mean(BMI,na.rm = TRUE) - 2*sd(BMI,na.rm = TRUE)
underweight.candidates <- which(BMI < lower.limit & patients$Smokes == "Smoker")
```
```{r}
write.csv(patients[underweight.candidates,], "underweight_candidates.csv")
```