I hereby claim:
- I am jmcastagnetto on github.
- I am jmcastagnetto (https://keybase.io/jmcastagnetto) on keybase.
- I have a public key whose fingerprint is 73A9 891B 6BAB 0D95 75AF 3759 03B2 0193 CD42 79DF
To claim this, I am signing this object:
require(XML) | |
require(reshape2) | |
# node content cleanup | |
cleanup <- function(node) { | |
val <- xmlValue(node) | |
if(is.character(val) | is.factor(val)) { | |
out <- gsub("'","", val, fixed=TRUE) | |
} else { | |
out <- val |
# Inspired by http://xkcd.com/1609/ | |
set.seed(1609) | |
food <- c("ice cream", "ham", "relish", | |
"pancakes", "ketchup", "cheese", | |
"eggs", "cupcakes", "sour cream", | |
"hot chocolate", "avocado", "skittles", | |
"wasabi", "tofu", "steak", "sweet potatoes") | |
nfood <- length(food) |
# BREXIT events and exchange rate of GBP -> USD | |
library(quantmod) | |
pd <- getFX("GBP/USD", | |
from="2016-01-01", | |
to="2016-06-30") | |
plot(GBPUSD, ylim=c(1.35,1.5), main="British Pounds per USD") | |
df <- data.frame( | |
date = index(GBPUSD), | |
rate = as.numeric(GBPUSD) |
I hereby claim:
To claim this, I am signing this object:
--- | |
title: "Example of conditional chunk evaluation" | |
author: "Jesús M. Castagnetto" | |
date: "2019-05-30" | |
output: | |
pdf_document: | |
toc: true | |
number_sections: true | |
html_document: | |
df_print: paged |
library(tidyverse) | |
df <- data.frame( | |
x1 = 0:2, x2 = 1:3, | |
y1 = rep(0, 3), y2 = rep(2, 3), | |
color = c("r", "w", "r")) | |
ggplot(df) + | |
geom_rect(aes(xmin = x1, xmax = x2, | |
ymin = y1, ymax = y2, | |
fill = color) |
# based on the example at: https://echarts4r.john-coene.com/articles/chart_types.html#treemap | |
# the JS example at: https://echarts.apache.org/examples/en/editor.html?c=treemap-show-parent | |
# and the documentation at: https://echarts.apache.org/en/option.html#series-treemap.type | |
library(tidyverse) | |
library(echarts4r) | |
# this data structure does not work with the changed function | |
# set.seed(13579) | |
# |
# Ref: https://twitter.com/Amit_Levinson/status/1187754568014336002 | |
set.seed(2019) | |
gen_grades <- function(n, avg, sd, min, max, nsmpl) { | |
smpl <- rnorm(nsmpl, avg, sd) | |
smpl <- smpl[smpl >= min & smpl <= max] | |
if (length(smpl) >= n) { | |
return(sample(smpl, n)) | |
} else { | |
stop(simpleError("Not enough sample data. Increase 'nsmpl'")) |
library(countrycode) | |
library(tidyverse) | |
library(ggrepel) | |
df <- readxl::read_excel("Sustainable_food_systems_global_index-1.xlsx", sheet = 1, skip = 5) | |
df <- df %>% | |
mutate( | |
region = countrycode(origin = "iso3c", | |
sourcevar = ISO3, |
library(tidyverse) | |
library(rvest) | |
url <- "http://www.sunat.gob.pe/indicestasas/uit.html" | |
uit_table <- html(url) %>% | |
html_node(xpath = "/html/body/div[2]/div/div[1]/div[4]/div[1]/div[1]/center/table") %>% | |
html_table(header = TRUE) %>% | |
janitor::clean_names() | |
uit_df <- uit_table %>% |