This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(magrittr) | |
library(cansim) | |
# For filtering later, here are the locations and products that we'll want | |
keep_GEO <- c("Canada") | |
keep_products <- c("Total Industrial product price index (IPPI), excluding energy and petroleum products", | |
"Plastic and rubber products [P32]", | |
"Lumber and other wood products [P41]", | |
"Fabricated metal products and construction materials [P63]", |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(readxl) | |
library(tidyverse) | |
library(magrittr) | |
library(rmapshaper) | |
# Shapefiles -------------------------------------------------------------- | |
# Federal Electoral Districts shapefile | |
shape_file_url <- "http://ftp.maps.canada.ca/pub/elections_elections/Electoral-districts_Circonscription-electorale/Elections_Canada_2019/federal_electoral_districts_boundaries_2019.shp.zip" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(magrittr) | |
library(cansim) | |
# For filtering later, here are the locations and products that we'll want | |
keep_GEO <- c("Canada", "Toronto, Ontario", "Ontario") | |
keep_products <- c("All-items", "Alcoholic beverages", "Apples", | |
"Transportation", "Public transportation", "Parking fees") | |
cansim_table <- "18-10-0004" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(magrittr) | |
ttc_gtfs <- tidytransit::feedlist %>% | |
dplyr::filter(t=="TTC GTFS") %>% | |
dplyr::pull(url_d) %>% | |
tidytransit::read_gtfs() | |
attach(ttc_gtfs) | |
routes %>% dplyr::inner_join(trips, by="route_id") %>% | |
dplyr::inner_join(stop_times) %>% | |
dplyr::inner_join(stops, by = "stop_id") %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(magrittr) | |
# Federal Electoral Districts shapefile | |
shape_file_url <- "http://ftp.maps.canada.ca/pub/elections_elections/Electoral-districts_Circonscription-electorale/federal_electoral_districts_boundaries_2015/federal_electoral_districts_boundaries_2015_shp_en.zip" | |
download.file(shape_file_url, | |
destfile = "data-raw/federal_electoral_districts_boundaries_2015_shp_en.zip", quiet = TRUE) | |
unzip("data-raw/federal_electoral_districts_boundaries_2015_shp_en.zip", exdir="data-raw/federal_electoral_districts_boundaries_2015_shp_en") | |
federal_shapefile <- sf::read_sf("data-raw/federal_electoral_districts_boundaries_2015_shp_en", | |
layer = "FED_CA_2_2_ENG") %>% | |
sf::st_transform(crs = "+init=epsg:4326") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url <- "https://www.elections.ca/res/rep/off/ovr2015app/41/data_donnees/pollresults_resultatsbureauCanada.zip" | |
pins::pin(url, name = "2015_fed_results_zip") | |
unzip(pins::pin_get("2015_fed_results_zip"), exdir=paste("data-raw", "pollresults", sep = "/")) | |
on_files <- list.files(path = "data-raw/pollresults", | |
pattern = "pollresults_resultatsbureau35[[:digit:]]{3}.csv", | |
full.names = TRUE) | |
federal_results <- do.call("rbind", lapply(on_files, function(.file){readr::read_csv(.file)})) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Supply-demand charts in R" | |
output: html_notebook | |
--- | |
```{r setup} | |
library(tidyverse) | |
library(devtools) | |
install_github("andrewheiss/reconPlots") | |
library(reconPlots) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pick_numbers <- function() { | |
trunc(runif(4, min = 1, max = 100)) | |
} | |
winning_number <- function(numbers) { | |
numbers[2:4][which.min(abs(numbers[2:4] - numbers[1]))] | |
} | |
data <- replicate(1000000, winning_number(pick_numbers())) | |
hist(data, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
data <- readxl::read_excel("Eco Ben Cleansed Passenger Counts v1.xlsx", | |
sheet = "Data") %>% | |
dplyr::transmute( # Shorten column names | |
passengers = `Station Passenger Count FINAL`, | |
delay = `System Minutes Delayed` | |
) | |
# Calculate current sd in delays |
NewerOlder