I hereby claim:
- I am plaudenslager on github.
- I am peterl (https://keybase.io/peterl) on keybase.
- I have a public key whose fingerprint is 49F8 140B F2A9 7183 480A 8AA8 1D66 F371 9A26 033D
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
##' Color-blind friendly palette | |
##' From \url{http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/} | |
##' @title Color-blind friendly palette | |
##' @param palette Choose "cb", "rcb", or "bly". cb is the Winston | |
##' Chang color blind palette; rcb is that palette in reverse; bly | |
##' puts the yellow and blue in the palette first. | |
##' @return Variations on an eight-color color-blind friendly palette. | |
##' @author Winston Chang / Kieran Healy | |
##' @export | |
my.colors <- function(palette="cb"){ |
stl_plotter <- function(title, data){ | |
# requires dataframe from expanded_stl | |
# plots graphics to files | |
theme_set(theme_minimal()) | |
p <- ggplot(data, aes(x=Date, y=sales)) | |
p1 <- p + geom_line() + ylab("Data") | |
p <- ggplot(data, aes(x=Date, y=trend)) |
expanded_stl <- function(ts_data, sales_data, dates){ | |
# requires ts data, plus the raw sales data and dates vectors | |
# returns a data.frame suitable for plotting with stl_plotter | |
data.stl <- stl(ts_data, s.window = 11, t.jump = 1) | |
ggdata <- data.frame(data.stl$time.series) | |
ggdata$sales <- sales_data | |
ggdata$Date <- dates | |
#ggmac.stl$Product <- "Mac" | |
return(ggdata) |
fiscal_Qtr <- function(date, first_month_in_FY=4){ | |
month = as.numeric(format(date, "%m")) | |
year = as.numeric(format(date, "%y")) | |
if (month < first_month_in_FY){ | |
fiscal_year = year | |
quarter = (13 - first_month_in_FY + month-1) %/% 3 + 1 | |
}else{ | |
fiscal_year = year + 1 | |
quarter = (month - first_month_in_FY) %/% 3 + 1 | |
} |
# Load dataset | |
setwd("~/Dropbox/work") | |
raw_data <- read.csv("2016-05-11 Trial Download Detail.csv", stringsAsFactors = FALSE) | |
str(raw_data) | |
head(raw_data) | |
tail(raw_data) |
library(dplyr) | |
# raw_data is a dataframe; probably imported from CSV or other file | |
# clean_data is the dataframe we intend to use in the analysis | |
# Signup.Date is a string that contains the date - in this case the format is "mm/dd/yyyy" | |
clean_data <- mutate(raw_data, Signup.Date = as.Date(Signup.Date, "%m/%d/%y")) |
library(dplyr) | |
# Signup.Date is original date information in Date format | |
# Signup.Week is beginning date of week that contains Signup.Date | |
# cut function can take other parameters instead of "weeks": "day", "week", "month", "quarter" and "year" | |
# adds a column of dates to the dataframe that groups data into week-long buckets | |
clean_data <- clean_data %>% mutate(Signup.Week = cut(Signup.Date, "weeks")) |
library(dplyr) | |
library(tidyr) | |
# sum_trialname contains product names, including three different versions of one product | |
# dropping everything after the first space gets me to a consistent product naming | |
# the extract function, by default, captures the initial alphanumeric data, and drops everything after the first non-alpha character | |
# by default, teh extract function also drops the original column (sum_trialname, in this case) | |
# Create a new column with clean, consistent product names | |
clean_data <- extract(clean_data, sum_trialname, "Product", remove=FALSE) |
# Look for a duplicate header in the rows | |
header_in_rows <- startsWith(raw_data[,1], substr(colnames(raw_data)[1], 1, 5)) | |
if(TRUE %in% header_in_rows){ | |
print(raw_data[header_in_rows,]) | |
raw_data <- filter(raw_data, !header_in_rows) | |
} |