This file contains hidden or 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
| # Calculation of hurricane damage as percentage of | |
| # real GDP in the US. | |
| # The data: | |
| # damage taken from: | |
| # https://www.wunderground.com/cat6/2017-us-hurricane-damages-206-billion-highest-record | |
| # real GDP taken from | |
| # https://fred.stlouisfed.org/series/GDPCA | |
| year <- c(2017,1893,2005,1928,1960,2012,1969,1947,1954,1945) | |
| # damage in billion of dollars, adjusted to 2017 dollars |
This file contains hidden or 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
| # x is a dataset, and one wants to construct a new dataset created by x minus the 5 "quartiles", | |
| # being 0%, 25%, 50%, 75% and 100% quantiles. | |
| # This constructs the data | |
| x <- rnorm(1e6) | |
| quart <- quantile(x) | |
| # The original code of one of my students. I loathed two things: | |
| # - the use of a for loop when one could use outer() | |
| # - the growing of an object | |
| oorspronkelijk <- function(x, quart){ |
This file contains hidden or 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(OECD) | |
| library(dplyr) | |
| library(ggplot2) | |
| ## Get the latest OECD data on decile ratios of gross earnings. | |
| ## This is the dataset that contains information on wage gaps. | |
| oecdData <- get_dataset("DEC_I") | |
| ## Prepare the plot data | |
| gwg <- |
This file contains hidden or 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
| # Currently roxygen 6.1.0 doesn't read the collate field correctly, so once you use @include anywhere | |
| # in your package, you run into problems. The error you get, is a 'Permission denied' error. If that | |
| # occurs, best thing to do for now is to install the previous version of roxygen until | |
| # the problem is solved. | |
| # | |
| # I've made a binary build for Windows available. You can download it manually from following link: | |
| # https://jorismeys.stackstorage.com/s/co8cKzyRemVHZef | |
| # Alas the filesharing I use doesn't allow automatic downloading through download.file(), so you | |
| # have to go to that link and click on Download to get the actual zip file. | |
| # |
This file contains hidden or 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 | |
| library(magrittr) | |
| library(purrr) | |
| #> | |
| #> Attaching package: 'purrr' | |
| #> The following object is masked from 'package:magrittr': | |
| #> | |
| #> set_names | |
| library(microbenchmark) |
This file contains hidden or 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(tidyr) | |
| library(ggplot2) | |
| # I look at 4 different rates here. The rate for the period 2000-2018 was approximately 3 mm / year. | |
| rates <- c(0.15,0.2,0.3, 0.4) | |
| # This creates a tibble (dataset) with the sea level rise until 2100 depending on the rate | |
| mydata <- tibble( | |
| years = seq(2018,2100, by=1), | |
| slow = seq_along(years)*rates[1], |
This file contains hidden or 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
| # Download median of regional timeseries | |
| temp <- readLines("https://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/time_series/HadCRUT.4.6.0.0.monthly_ns_avg.txt") | |
| temp <- data.frame(do.call(rbind, strsplit(temp," ")), | |
| stringsAsFactors = FALSE) | |
| temp[-1] <- lapply(temp[-1], as.numeric) | |
| temp$year <- as.numeric(gsub("/.*","",temp[,1])) | |
| temp$month <- as.numeric(gsub(".*/","",temp[,1])) | |
| temp$time <- temp$year + temp$month/12.5 |
This file contains hidden or 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
| ## ----setup, include=FALSE------------------------------------------------ | |
| knitr::opts_chunk$set(echo = TRUE) | |
| # Needed so the code runs later on. | |
| datadir <- "pottmp_data" | |
| fnames <- paste("pottmp",1980:2019,"nc", sep = ".") | |
| ## ----Download information, eval=FALSE------------------------------------ | |
| ## # ONLY RUN THIS ONCE TO DOWNLOAD THE DATA | |
| ## # This downloads 39 files of appx 144 Mb each! | |
| ## # Create a directory to store the data. |
This file contains hidden or 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(shiny) | |
| # Define server logic required to draw a histogram | |
| shinyServer(function(input, output) { | |
| mysamples <- reactive({ | |
| fdist <- switch(input$dist, | |
| Normal = rnorm, | |
| Exponential = rexp, | |
| Poisson = function(n) rpois(n,4)) |
This file contains hidden or 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
| # Plot UAH monthly temperatures | |
| # Joris Meys | |
| # Date last modified: 2019-11-18 | |
| # Create a temporary filename | |
| fname <- tempfile() | |
| # Download data into the temporary file | |
| download.file("https://www.nsstc.uah.edu/data/msu/v6.0/tlt/uahncdc_lt_6.0.txt",destfile = fname) |
OlderNewer