Skip to content

Instantly share code, notes, and snippets.

View jlopezper's full-sized avatar

Jorge López Pérez jlopezper

View GitHub Profile
@jlopezper
jlopezper / library_visits.R
Last active July 25, 2018 23:07
Using CKANR API with OpenDataBCN
# Load libraries
library(ckanr)
library(XML)
library(ggmap)
library(dplyr)
# API Setup
ckanr_setup(url = "http://opendata-ajuntament.barcelona.cat/data")
runs <- 100000
threshold <- 1000
Res = vector(mode = "numeric")
for (k in 1:runs){
i <- 1
v <- vector(mode = "numeric")
while (sum(v) < threshold) {
v[i] <- runif(1,0,1000)
# install.packages("devtools")
devtools::install_github("ropenspain/opendataes")
library(opendataes)
determine_number <- function(x) {
check_read <- function(data) !all(names(data) %in% c('name', 'format', "URL"))
has_url_col <- vapply(x[[2]], check_read, logical(1))
number_of_reads <- sum(has_url_col)
library(httr)
library(dplyr)
library(magrittr)
library(purrr)
get_holidays <- function(country_code, year) {
# Build URL
url <- parse_url("http://date.nager.at")
url$path <- paste0("api/v1/get/", country_code, "/", year)
# load packages
library(readr)
library(tidyr)
library(ggplot2)
library(gifski)
library(gganimate)
library(dplyr)
# load data
tst <- readr::read_csv("https://elpais.com/especiales/2019/elecciones-generales/encuestas-electorales/ficheros/tabla.csv?1554807308",
library(tidyverse)
library(sf) # classes and functions for vector data
library(raster) # classes and functions for raster data
library(spData) # load geographic data
library(spDataLarge) # load larger geographic data
renta <- readr::read_csv2("./data/data_renta.csv", col_types = cols(
cp = col_character(),
numero_declaraciones = col_number(),
renta_media = col_number(),
``` r
wilcox_test <- function(x, y) {
# build the dataframe
df <- data.frame(x, y)
# calculate the absolute difference, sign and rank it
df$dif <- abs(x - y)
df <- subset(df, dif != 0)
df$sign <- sign(df$x - df$y)
# Ugly code for tacking Covid-19 in Spain
# load libraries
library(readr)
library(ggplot2)
library(tidyr)
library(dplyr)
library(grid)
library(gridExtra)
library(tabulizer)
library(dplyr)
library(tidyr)
library(ggplot2)
library(R0)
library(EpiEstim)
# read data
url_confirmed <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
corona <- data.table::fread(url_confirmed) %>% as_tibble()
corona[c("Province/State", "Lat", "Long")] <- NULL
library(data.table)
library(dtplyr)
library(dplyr, warn.conflicts = FALSE)
library(microbenchmark)
library(ggplot2)
set.seed(123)
df <- data.frame(
letters = sample(c('A', 'B', 'C'), size = 3e6, replace = TRUE, prob = c(.5, .4, .1)),
number = sample(c(1:5), size = 3e6, replace = TRUE)