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
# Set a seed | |
set.seed(500) | |
library(MASS) | |
data <- Boston | |
# Check that no data is missing | |
apply(data,2,function(x) sum(is.na(x))) | |
# Train-test random splitting for linear model |
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
### Title: Back to basics: High quality plots using base R graphics | |
### An interactive tutorial for the Davis R Users Group meeting on April 24, 2015 | |
### | |
### Date created: 20150418 | |
### Last updated: 20150423 | |
### | |
### Author: Michael Koontz | |
### Email: mikoontz@gmail.com | |
### Twitter: @michaeljkoontz | |
### |
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 the latest version of DiagrammeR from GitHub | |
devtools::install_github("rich-iannone/DiagrammeR") | |
# Ensure that the package is loaded | |
library("DiagrammeR") | |
# So, here's a script that essentially takes an empty graph series, and | |
# creates a new graph on each new day it is triggered. It will create | |
# random nodes each time it's triggered and add those nodes to the graph | |
# belonging to the current day. Throughout the script, '_SELF_' refers |
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
# Here are a few methods for getting text from PDF files. Do read through | |
# the instructions carefully! NOte that this code is written for Windows 7, | |
# slight adjustments may be needed for other OSs | |
# Tell R what folder contains your 1000s of PDFs | |
dest <- "G:/somehere/with/many/PDFs" | |
# make a vector of PDF file names | |
myfiles <- list.files(path = dest, pattern = "pdf", full.names = TRUE) |
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
getCIK = function(ticker) { | |
stopifnot(is.character(ticker)) | |
uri = "http://www.sec.gov/cgi-bin/browse-edgar" | |
response = getForm(uri,CIK=ticker,action="getcompany") | |
html = htmlParse(response) | |
CIKNode = getNodeSet(html, "//acronym[@title=\"Central Index Key\"][text() = \"CIK\"]") | |
CIKNodeText = sapply(CIKNode, function(x) xmlValue(getSibling(getSibling(x)))) | |
CIK = sub(" .*","",CIKNodeText) | |
CIK = sub("^0*","",CIK) |
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
#devtools::install("jeroenooms/V8") | |
library("V8") | |
library(pipeR) | |
ct = new_context("window") | |
# min.js gives me a call stack size error but non-min works fine | |
ct$source( | |
"https://raw.githubusercontent.com/morganherlocker/turf/master/turf.js" | |
) | |
# one of the examples from turf API docs |
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
## Analyze R packages for popularity, using pagerank algorithm | |
# Inspired by Antonio Piccolboni, http://piccolboni.info/2012/05/essential-r-packages.html | |
library(miniCRAN) | |
library(igraph) | |
library(magrittr) | |
# Download matrix of available packages at specific date ------------------ |
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(rgdal) | |
library(rgeos) | |
library(ggplot2) | |
library(readr) | |
library(tidyr) | |
library(dplyr) | |
library(grid) | |
us <- readOGR("us_states_hexgrid.geojson", "OGRGeoJSON") |
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
# Proof of concept of using V8 to parse HTML in R | |
# Example taken from rvest readme | |
# Jeroen Ooms, 2015 | |
library(V8) | |
stopifnot(packageVersion("V8") >= "0.4") | |
# Get Document | |
html <- paste(readLines("http://www.imdb.com/title/tt1490017/"), collapse="\n") |
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(e1071) | |
library(gganimate) | |
# parameters for the simulation | |
ntimes <- 100 | |
nseries <- 20 | |
# construct tibble storing simulation | |
tbl <- tibble( |
NewerOlder