-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_Summary_stats.Rmd
More file actions
60 lines (43 loc) · 1.19 KB
/
2_Summary_stats.Rmd
File metadata and controls
60 lines (43 loc) · 1.19 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: "Exercise 2 - Summary statistics"
output: html_document
---
```{r load_libraries, include=FALSE}
library(tidyverse)
```
R has a number of inbuilt functions to calculate summary statistics. Each of them takes a set of
numbers and reduces them down to a single summary value. For this exercise, we will be asking you
to work with two inbuilt datasets, `sleep` and `InsectSprays`.
```{r datasets}
#Learn about the datasets
?sleep
?InsectSprays
```
> Calculate summary statistics for each group in the data.
Calculate the:
* Mean - `mean()`
* Median - `median()`
* Variance - `var()`
* Standard deviation - `sd()`
* Interquartile range - `IQR()`
for each experimental group in the `sleep` and `InsectSprays` data set.
```{r summary_stats}
# Summarise sleep
sleep %>%
group_by(_____) %>%
summarise(_____)
# Summarise InsectSprays
InsectSprays %>%
_____
```
Are the summary statistics useful in understanding the data?
How does this compare with the plots of data distributions we have been producing?
```{r plotting_distributions}
# Boxplot for sleep data
sleep %>%
ggplot(aes(x = group, y = extra)) +
geom_boxplot()
# Boxplot for InsectSprays data
InsectSprays %>%
_____
```