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
# Define the function | |
ggd.qqplot = function(pvector, main=NULL, ...) { | |
o = -log10(sort(pvector,decreasing=F)) | |
e = -log10( 1:length(o)/length(o) ) | |
plot(e,o,pch=19,cex=1, main=main, ..., | |
xlab=expression(Expected~~-log[10](italic(p))), | |
ylab=expression(Observed~~-log[10](italic(p))), | |
xlim=c(0,max(e)), ylim=c(0,max(e))) | |
lines(e,e,col="red") | |
} |
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
# Define the function | |
ggd.qqplot = function(pvector, main=NULL, ...) { | |
o = -log10(sort(pvector,decreasing=F)) | |
e = -log10( 1:length(o)/length(o) ) | |
plot(e,o,pch=19,cex=1, main=main, ..., | |
xlab=expression(Expected~~-log[10](italic(p))), | |
ylab=expression(Observed~~-log[10](italic(p))), | |
xlim=c(0,max(e)), ylim=c(0,max(e))) | |
lines(e,e,col="red") | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> |
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
# assumes codes are known beforehand | |
codes <- c("MSFT", "1234") | |
urls <- paste0("http://www.google.com/finance/historical?q=NASDAQ:", | |
codes,"&output=csv") | |
paths <- paste0(codes,"csv") | |
missing <- !(paths %in% dir(".", full.name = TRUE)) | |
missing | |
# simple error handling in case file doesn't exists | |
downloadFile <- function(url, path, ...) { |
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(lubridate) | |
library(data.table) | |
library(plyr) | |
library(dplyr) | |
# create data folder | |
dataDir <- paste0("data",format(Sys.Date(),"_%Y_%m_%d")) | |
if(file.exists(dataDir)) { | |
unlink(dataDir, recursive = TRUE) | |
dir.create(dataDir) |
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(lubridate) | |
library(stringr) | |
library(reshape2) | |
library(plyr) | |
library(dplyr) | |
# read all csv files and merge | |
# assumes files exist in data folder | |
dataDir <- "data" | |
files <- dir(dataDir, full.name = TRUE) |
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(lubridate) | |
library(stringr) | |
library(reshape2) | |
library(plyr) | |
library(dplyr) | |
# create data folder | |
dataDir <- paste0("data","_",format(Sys.Date(),"%Y-%m-%d")) | |
if(file.exists(dataDir)) { | |
unlink(dataDir, recursive = TRUE) |
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(knitr) | |
library(lubridate) | |
library(stringr) | |
library(reshape2) | |
library(plyr) | |
# create data folder | |
dataDir <- paste0("data","_",format(Sys.Date(),"%Y-%m-%d")) | |
if(file.exists(dataDir)) { | |
unlink(dataDir, recursive = TRUE) |
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
## set up variables | |
size <- 36000 | |
numUsers <- 4900 | |
# roughly each user has 7 sessions | |
numSessions <- (numUsers / 7) - ((numUsers / 7) %% 1) | |
## create data frame | |
set.seed(123457) | |
userIds <- sample.int(numUsers, size=size, replace=TRUE) | |
ssIds <- sample.int(numSessions, size=size, replace=TRUE) |
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
MyData <- data.frame(Year=seq(2000,2009)) | |
# year variables | |
dim <- length(MyData$Year) | |
yMat <- matrix(NA, nrow=dim, ncol=dim) | |
for(i in 1:dim) { | |
yMat[i,] <- rbind(t(MyData)) # transpose | |
} | |
yMat |
OlderNewer