-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcake_data_analysis.Rmd
More file actions
118 lines (96 loc) · 2.24 KB
/
cake_data_analysis.Rmd
File metadata and controls
118 lines (96 loc) · 2.24 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
title: "cake_data_analysis"
author: "VM"
date: "09/11/2020"
output:
html_document:
number_sections: yes
toc: yes
toc_float: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Read data first and load libraries
```{r}
library(tidyverse)
library(here)
library(janitor)
clean_data <- read_csv("~/dirty_data_project/task2/clean_data/clean_cake_data.csv")
wide_data <- read_csv("~/dirty_data_project/task2/clean_data/clean_wide_cake_data.csv")
long_data <- read_csv("~/dirty_data_project/task2/clean_data/clean_long_cake_data.csv")
```
```{r}
head(clean_data)
head(wide_data)
head(long_data)
```
There are a lot of NA as these ingredient were not used in cake, therefore,
they were left and further ignored in analysis.
# Q1
## Which cake has the most cocoa in it?
```{r}
clean_data %>%
filter(ingredient == "cocoa") %>%
remove_empty("cols")
wide_data %>%
select(cakes, cocoa_tablespoon) %>%
drop_na(cocoa_tablespoon) %>%
arrange(desc(cocoa_tablespoon)) %>%
head(1)
long_data %>%
group_by(ingredient) %>%
filter(ingredient == "cocoa") %>%
slice_max(value)
```
# Q2
## For sponge cake, how many cups of ingredients are used in total?
```{r}
clean_data %>%
select(measure, ingredient, sponge) %>%
filter(measure == "cup") %>%
drop_na() %>%
count()
wide_data %>%
filter(cakes == "sponge") %>%
remove_empty("cols") %>%
select(matches("cup$")) %>%
ncol()
long_data %>%
filter(cakes == "sponge") %>%
filter(measure == "cup") %>%
summarise(count = n_distinct(value))
```
# Q3
## How many ingredients are measured in teaspoons?
```{r}
clean_data %>%
filter(measure == "teaspoon") %>%
n_distinct()
wide_data %>%
select(matches("teaspoon")) %>%
ncol()
long_data %>%
group_by(ingredient) %>%
filter(measure == "teaspoon") %>%
summarise(count = n_distinct(ingredient)) %>%
count()
```
# Q4
## Which cake has the most unique ingredients?
```{r}
long_data %>%
group_by(cakes) %>%
drop_na() %>%
summarise(count = n_distinct(ingredient)) %>%
slice_max(count)
```
# Q5
## Which ingredients are used only once?
```{r}
long_data %>%
group_by(ingredient) %>%
drop_na() %>%
count(ingredient) %>%
filter(n == 1)
```