- Author: Thomas Girke
- Last update: 18-Nov-2020
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
rectangles <- function(m, rowfirst = TRUE) { | |
if (rowfirst) | |
m <- t(m) | |
n <- length(m) | |
nrow <- nrow(m) | |
ncol <- ncol(m) | |
rowindex <- seq_len(nrow) | |
colindex <- seq_len(ncol) | |
h <- hashtab() |
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(data.table) | |
shapes <- function(m) { | |
n <- length(m) | |
nrow <- nrow(m) | |
index <- seq_len(n) | |
rows <- ((index - 1L) %% nrow) + 1L | |
cols <- ((index - 1L) %/% nrow) + 1L | |
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
funz <- function(x) { | |
if (!is.character(x) || length(x) != 1L || is.na(x)) | |
stop("`x` must be a scalar character that's not NA.") | |
middle <- character() | |
go <- TRUE | |
i <- 1L | |
while(go) { | |
exploded <- c(")", middle, "\"") | |
delim <- paste(exploded, collapse = "") | |
if (grepl(delim, x, fixed = TRUE)) { |
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(data.table) | |
?`[.data.table` | |
DT <- data.table(x=rep(c("b","a","c"),each=3), y=c(1,3,6), v=1:9) | |
X <- data.table(x=c("c","b"), v=8:7, foo=c(4,2)) | |
colnames(DT) | |
# [1] "x" "y" "v" |
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://raw.githubusercontent.com/TimTaylor/census_pop_2021/main/output/census-2021-england-and-wales-total-population.csv" | |
(dat <- read.csv(url)) | |
# add start and end columns | |
start <- sub("\\[([0-9]+), .+)", "\\1", dat$age_category) | |
end <- sub(".+, (.+))", "\\1", dat$age_category) | |
dat$start <- as.double(start) | |
dat$end <- as.double(end) | |
# function to bootstrap with a single category |
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
# Note the following is not 100% foolproof as it assumes the table entries are all on one line. | |
# This will need refining to deal with when this is not the case but may be sufficient for the | |
# question. | |
# h/t to https://github.com/hrbrmstr/fish-stocking-pdf-data-wrangling/blob/main/main.R | |
# who's code I'd seen just the other day doing similarish type stuff | |
library(rvest) | |
library(pdftools) |
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
# parameters -------------------------------------------------------------- | |
N <- 1000 # network size | |
avk <- 7 # desired average degree | |
gamma <- 0.25 # recovery rate | |
tau <- 0.27 # per-edge infection rate | |
max_time <- 50 # maximum simulation length | |
i0 <- 10 # initial number of infected individuals | |
# ------------------------------------------------------------------------- |
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
# parameters | |
N <- 1000 # network size | |
avk <- 7 # desired average degree | |
gamma <- 0.25 # recovery rate | |
tau <- 0.27 # per-edge infection rate | |
max_time <- 50 # maximum simulation length | |
i0 <- 10 # initial number of infected individuals | |
# build erdos-renyi random-graph | |
network <- matrix(0L, nrow = N, ncol = N) |
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
# Based on this stackoverflow answer (https://stackoverflow.com/a/57709169) | |
# from Valeri Voev | |
#' Return quoted arguments of given expression | |
#' | |
#' @param args Expression such `x`, `"x"`, `c(x, y)` or `c("x", "y")`. | |
#' | |
#' @return The quoted arguments. | |
#' | |
#' @examples |
NewerOlder