Skip to content

Instantly share code, notes, and snippets.

View dickoa's full-sized avatar

Ahmadou Dicko dickoa

View GitHub Profile
@dickoa
dickoa / up_brewer.R
Last active August 27, 2023 16:31
Brewer method unequal probabilities speed up
up_brewer <- function(pik, eps = 1e-06) {
if (any(is.na(pik)))
stop("there are missing values in the pik vector")
list <- pik > eps & pik < 1 - eps
pikb <- pik[list]
s <- pik
N <- as.integer(length(pikb))
sb <- vector(mode = "double", length = N)
r <- .C("C_up_brewer", pikb, N, result = sb)
s[list] <- r$result
@dickoa
dickoa / dtm_api_test.R
Created June 21, 2024 17:15
Pull DTM data from API using R and httr2
library(tidyverse)
library(httr2)
library(cli)
url <- 'https://dtmapi.iom.int/api/IdpAdmin2Data/GetAdmin2Data'
payload <- list(operation = "",
countryName = "Afghanistan",
admin0Pcode = "",
reportingDate = list(fromDate = "2018-12-31", toDate = "2023-05-31"),
@dickoa
dickoa / beginner_intro.R
Created August 29, 2024 07:15
Intro R code to copy
library(tidyverse) # copy this part only if you don't have it yet
pop <- tibble(year = rep(2023, 5),
coa = c("Sudan", "Burkina Faso", "DRC", "Syria", "Yemen"),
pop = c(47.5, 22.9, 103.2, 22.1, 33.7),
idp = c(9.1, 2.3, 6.3, 7.2, 4.5))