First define the data - reference: https://www.enz.org/
Evolution of average house prices between 2013 and 2017 in New Zealand.
library(dplyr); library(tidyr)
df <- tibble::as.tibble(read.table("./data.txt", header=T, sep=";",
stringsAsFactors=F))
with_selection <- function(df, cities=c("Auckland")) {
df %>% filter(City %in% cities) %>%
filter(grepl("All .* Area", Surburb)) %>%
gather(AvgHousePrices_2013:AvgHousePrices_2017,
key = "year", value = "AvgHousePrices") %>%
separate(year, into = c("todrop", "year"), sep="_", convert=T) %>%
select(-todrop)
}
df_akl <- df %>% with_selection()
df_wel <- df %>% with_selection(cities = c("Wellington"))
df_chc <- df %>% with_selection(cities = c("Christchurch"))