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(readr) | |
library(suncalc) | |
library(dplyr) | |
library(ggplot2) | |
library(ggthemes) | |
library(lubridate) | |
library(tidyr) | |
quake10yr <- c("https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2020-02-01&enddate=2021-03-01T0:00:00", | |
"https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2019-02-01&enddate=2020-02-01", |
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(rvest) | |
target_url <- "https://www.publicservice.govt.nz/resources/proactive-releases/" | |
webpage <- target_url %>% read_html() | |
links <- webpage %>% html_nodes("a") %>% html_attr("href") | |
link_text <- webpage %>% html_nodes("a") %>% html_text() | |
link_set <- data.frame(links, link_text, stringsAsFactors = FALSE) | |
if(file.exists("linkcurrent.csv")){ | |
linkcurrent <- read.csv("linkcurrent.csv", stringsAsFactors = FALSE) | |
newlinks <- link_set[!link_set$links %in% linkcurrent$links,] | |
} else { |
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
# works through | |
# https://www.health.govt.nz/news-media/media-releases?page=1 and subsequent pages | |
library(rvest) | |
library(dplyr) | |
library(stringr) | |
table_fetch <- function(x){ | |
url_loc <- paste0("https://www.health.govt.nz",x) | |
page_obj <- url_loc %>% read_html() |
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(readr) | |
library(suncalc) | |
library(dplyr) | |
library(ggplot2) | |
library(ggthemes) | |
library(lubridate) | |
library(tidyr) | |
quake10yr <- c("https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2020-02-01&enddate=2021-03-01T0:00:00", | |
"https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2019-02-01&enddate=2020-02-01", |
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
############ collection | |
## assumes the working directory is the folder the script is in, and is set to the same for future runs of the file. | |
# This also assumes you have twitter developer credientals, and have run the create_token() function in the rtweet package | |
# to authorise r to access Twitter. This stores the credentials in an environmental variable loaded at startup so they are | |
# not exposed in the script | |
# as an alternative, if using a Mac or PC, and the httpuv package is installed, you can interactively authorise the script | |
# at run time | |
# these packages need to be already installed in order to be loaded and used |
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(readr) | |
library(suncalc) | |
library(dplyr) | |
library(ggplot2) | |
library(ggthemes) | |
library(lubridate) | |
quake10yr <- c("https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2020-02-01&enddate=2021-03-01T0:00:00", | |
"https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2019-02-01&enddate=2020-02-01", | |
"https://quakesearch.geonet.org.nz/csv?bbox=165.5420,-49.1817,-178.9893,-32.2871&minmag=0&mindepth=0&startdate=2018-01-01&enddate=2019-02-01", |
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(readr) | |
library(dplyr) | |
library(lubridate) | |
library(ggplot2) | |
library(ggthemes) | |
# arrivals from provisional daily arrivals stats NZ | |
# postive MiQ data from MoH case demographics |
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
# example code for processing the XML New Zealand elections final data | |
# party and cadidate vote. | |
# source: https://electionresults.govt.nz/electionresults_2020/xml/ | |
# | |
# preceding this code was downloading a local copy of the NZ election | |
# XML provisional results using wget. | |
# Before that, since I am on a Mac, was using homebrew to install wget | |
# then I ran the terminal command | |
# wget -r -np -k https://electionresults.govt.nz/electionresults_2020/xml/ |
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(dplyr) | |
library(ggplot2) | |
library(ggthemes) | |
library(maps) | |
library(mapdata) | |
combined <- read.csv("combined.csv", stringsAsFactors = FALSE) | |
top_support <- max(combined$vote) | |
# keep in mind one polling place can provide for multiple electorates |
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
# example code for processing the XML New Zealand elections provisional data | |
# party vote only, but is extendable to cadidate vote. | |
# source: https://electionresults.govt.nz/electionresults_2020_preliminary/xml/ | |
# | |
# preceding this code was downloading a local copy of the NZ election | |
# XML provisional results using wget. | |
# Before that, since I am on a Mac, was using homebrew to install wget | |
# then I ran the terminal command | |
# wget -r -np -k https://electionresults.govt.nz/electionresults_2020_preliminary/xml/ |