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
# Load libraries | |
library(ckanr) | |
library(XML) | |
library(ggmap) | |
library(dplyr) | |
# API Setup | |
ckanr_setup(url = "http://opendata-ajuntament.barcelona.cat/data") |
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
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) |
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
# 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) |
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(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) |
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
# 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", |
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(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(), |
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
``` 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) |
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
# Ugly code for tacking Covid-19 in Spain | |
# load libraries | |
library(readr) | |
library(ggplot2) | |
library(tidyr) | |
library(dplyr) | |
library(grid) | |
library(gridExtra) | |
library(tabulizer) |
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(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 |
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) | |
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) |
OlderNewer