This file contains hidden or 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
# Simple tibble | |
d <- tibble(a1="foo", | |
a2="bar") | |
# Want to make a new column called "new" and unite all the "a*" columns together | |
newcol <- "new" | |
startchar <- "a" | |
unite(d,col=newcol,starts_with(startchar)) # Yay |
This file contains hidden or 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
# General data manipulation | |
library(tidyverse) | |
# Spatial data | |
library(sf) | |
# Thematic maps | |
library(tmap) |
This file contains hidden or 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
# ignoring time=t, just modelling on dx for simplicity | |
frecent3 <- function(rank,dx){ | |
a = 6.1625 | |
cc = 1.6724 | |
b = 0.2882 | |
return(( a/(1e-04 * dx + cc)+b) * rank) | |
} |
This file contains hidden or 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(sf) | |
library(mapview) | |
library(furrr) | |
library(raster) | |
plan(multiprocess) | |
ex = extent(c(xmin=-112,xmax=155,ymin=-44,ymax=-10)) |
This file contains hidden or 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
# Demonstration - Downloading and animating ACCESS forecast data | |
# [email protected] | |
# General functions, including str_replace, map | |
library(tidyverse) | |
# threddscrawler is a useful package for parsing THREDDS data servers | |
# Install it with: | |
# devtools::install_github("BigelowLab/threddscrawler") | |
library(threddscrawler) |
This file contains hidden or 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("reticulate") | |
library(tidyverse) | |
library(purrr) | |
# We use the python "holidays" package for the basic holidays | |
# Installed it using pip first | |
holidays <- import("holidays") | |
tas_holidays <- holidays$Australia(prov="TAS") | |
# List of all dates from 2000 to 2018 |
This file contains hidden or 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
data = tibble(foo=c("Bah","Fuzz")) | |
my_column="foo" | |
data %>% filter(!!my_column := "Bah") |
This file contains hidden or 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
## Load required packages | |
# you will need to install these, first do | |
# eg. install.packages("tidyverse") | |
# etc. to install them one by one | |
library(tidyverse) | |
library(httr) | |
library(sf) | |
library(tmap) |
This file contains hidden or 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(raster) | |
library(jpeg) | |
# Spherical environment mapping hillshade function | |
getv=function(i,a,s){ | |
ct = dim(i)[1:2]/2 | |
sx = values(s)/90 * ct[1] | |
sy = values(s)/90 * ct[2] | |
a = values(a) * 0.01745 | |
px = floor(ct[1] + sx * -sin(a)) |
This file contains hidden or 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(rjson) | |
library(httr) | |
turl="https://iowadems-caucussitecdn-prod2.azureedge.net/api/statecandidateresults" | |
a=GET(turl) | |
arr=c(content(a)$StateResults[[1]]$WinPercentage,content(a)$StateResults[[2]]$WinPercentage,content(a)$StateResults[[3]]$WinPercentage) | |
nam=c(content(a)$StateResults[[1]]$Candidate$DisplayName,content(a)$StateResults[[2]]$Candidate$DisplayName,content(a)$StateResults[[3]]$Candidate$DisplayName) | |
colr=c(content(a)$StateResults[[1]]$Candidate$Color,content(a)$StateResults[[2]]$Candidate$Color,content(a)$StateResults[[3]]$Candidate$Color) | |
rar=round(arr,3)*100 | |
barplot(arr,names.arg=nam,col=colr) |