Skip to content

Instantly share code, notes, and snippets.

@drewgriffith15
drewgriffith15 / forecastio.R
Created January 26, 2015 18:42
Blizzard Warning - Calling the Forecast.io API
############################################
# Load all necessary R packages
# library(devtools)
# install_github("hrbrmstr/Rforecastio")
library(Rforecastio)
library(ggplot2)
library(plyr)
@drewgriffith15
drewgriffith15 / FibonacciRetracements.R
Created January 16, 2015 20:55
Fibonacci Retracements in R
###############################################################################
# Load Systematic Investor Toolbox (SIT)
# http://systematicinvestor.wordpress.com/systematic-investor-toolbox/
###############################################################################
setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
#library(griffun)
load.packages('forecast,quantmod,lmtest,TTR')
@drewgriffith15
drewgriffith15 / DateFormats.R
Last active August 29, 2015 14:13
Handling Dates in R
# Sample dates
dates <- c("09/27/99", "03/15/08")
newDates <- as.Date(dates, format = "%m/%d/%y") # <-- Must change the format based on the format of what's being referenced
newDates # R output will be ISO standard dates in the format "%Y-%m-%d"
# Similar example to the last, but must be handled differently
dates <- c("09/27/1999", "03/15/2008")
newDates <- as.Date(dates, format = "%m/%d/%Y") # <-- the only difference here is the "Y" is capitalized
newDates # R output will be ISO standard dates in the format "%Y-%m-%d"
@drewgriffith15
drewgriffith15 / sorting_with_parameters.sql
Last active August 29, 2015 14:13
A Different Way to Sort Based on Parameters in SSRS
USE AdventureWorks2012
DECLARE @DefaultSort VARCHAR(max) = 'SalesPerson' -- SSRS parameter
DECLARE @tblSales AS TABLE (
SalesPersonID INT,
SalesOrderID INT,
SalesYear VARCHAR(4)
);
BEGIN
@drewgriffith15
drewgriffith15 / reverse_name.R
Created March 26, 2014 15:54
Reverse First and Last Name
reverse_name <- function(x, p="TRUE"){
require(stringr); require(Hmisc)
if (p == "TRUE"){
#x = str_replace_all(x, "[^[:print:]]", " ")
x = str_replace_all(x, "[^a-zA-Z.-]", " ") #keep periods and hyphens
la = capitalize(substr(str_trim(x, side = "both"),1,
str_locate(x, " ")-1))
fi = capitalize(substr(str_trim(x, side = "both"),
str_locate(x, " ")+1,str_length(x)))
out = str_trim(paste(fi,la), side = "both")
# ANALYSIS OF FIP vs ERA FOR 2013 (AS OF 20130604)
require(toolbox)
load.packages('stringr,sqldf')
setwd("~") #;getwd()
# SP - Standard Pitching
SP = read.csv("SP2013.CSV", strip.white = TRUE)
head(SP)
# Used for 2013 Draft Strategy
require(toolbox)
load.packages('stringr,sqldf')
setwd("~") #;getwd()
# SP - Standard Pitching
# 2011-2012 filtered by innings pitched
# Data compiled from http://www.baseball-reference.com/
SP = read.csv("SP.csv", strip.white = TRUE)
head(SP)
# Used for 2013 Draft Strategy
require(toolbox)
load.packages('stringr,sqldf,toolbox')
setwd("~") #;getwd()
# SB - Standard Batting
# 2011-2012 filtered by qualifying plate appearances
SB = read.csv("SB.csv", strip.white = TRUE)
head(SB)
@drewgriffith15
drewgriffith15 / extendForecast.R
Last active December 10, 2015 20:48
Adding future dates to a forecast
#' Adding future dates to a forecast
#'
#' @param dates the dates of the historical values
#' @param forecast a vector of forecasted values
#'
#' @keywords forecast, dates
#' @export
#' @examples
#' ##NULL
extendForecast <- function(dates, forecast) {
@drewgriffith15
drewgriffith15 / WordCloud.R
Created December 13, 2012 03:25
Working on my CV a little bit and got sidetracked...
############### DREWGRIFFITH15############### remove objects
rm(list = ls())
# load toolbox
install_github("toolbox", "drewgriffith15")
require(toolbox)
# load packages
load.packages("tm,wordcloud,RColorBrewer")