Skip to content

Instantly share code, notes, and snippets.

View bpbond's full-sized avatar

Ben Bond-Lamberty bpbond

View GitHub Profile
@bpbond
bpbond / orcid_coauthors.R
Last active March 4, 2023 13:49
Extract coauthor names from downloaded ORCID data
# BBL 2023-03-03
library(bib2df)
library(stringr)
# Read in Bibtex file downloaded from ORCID
x <- bib2df("~/Downloads/works.bib")
# Usually we're only interested in last five years or something like that
x$YEAR <- as.numeric(x$YEAR)
@bpbond
bpbond / random_random_forest.R
Last active January 19, 2022 14:44
Random Forest on random data
# Makes the inset plot shown in https://twitter.com/BenBondLamberty/status/1483560012844838922?s=20
set.seed(21)
n <- 750
x <- data.frame(x = runif(n))
for(vn in 1:70) {
x[paste0("v", vn)] <- runif(n)
}
@bpbond
bpbond / pi_darts.R
Last active November 6, 2019 00:55
Approximate pi by throwing darts
library(tibble)
library(ggplot2)
# Imagine a circle inscribed in a unit square
# We can converge (slowly) on the value of pi by throwing random darts
# at this target; counting how many fall in versus out of the circle;
# and using the resulting approximate area ratio to calculate pi.
set.seed(12345)