-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexercise6_solutions.qmd
32 lines (21 loc) · 1.2 KB
/
exercise6_solutions.qmd
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
# Exercise 6 solutions
```{r setup, include = FALSE}
pacman::p_load(tidyverse, readxl)
housing_market <- read_csv("saved_data/housing_market_tidy.csv")
disposable_income <- read_csv("saved_data/disposable_income.csv")
living_wage_long <- read_csv("saved_data/living_wage_long.csv")
```
## Question
Combine all three OBR datasets (housing market, disposable income and living wage) together to create one complete dataset, `obr_data.`
### Solution {.unnumbered}
Use `full_join` to combine the housing and disposable data by year and quarter, then pipe to apply `full_join` to the resulting data and add the living wage, joining by year. As there are multiple year rows in the housing and disposable income data, include the argument `muliple = "all"` to ensure the living wage variable is repeated for each quarter.
```{r join obr data}
# full join the housing and labour market data
obr_data <- full_join(housing_market, disposable_income,
by = c("year", "quarter")) %>%
# join this data to the living wage
full_join(., living_wage_long, by = "year", multiple = "all")
```
```{r save obr_data for future notes, echo = FALSE}
write_csv(obr_data, file = "saved_data/obr_data.csv")
```