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
<!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 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 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 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 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 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 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 |
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
# | |
# getUpdatedCM aims to extend a confusion matrix | |
# by adding model errors to the last column and use errors to the last row. | |
# | |
# Usage | |
# getUpdatedCM(cm) | |
# | |
# last modified on Feb 8, 2015 | |
# |
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
# | |
# updateCM aims to extend a confusion matrix | |
# by adding model errors to the last column and use errors to the last row. | |
# Both square and non-square matrices are supported | |
# | |
# Usage | |
# set.seed(1) | |
# actual = ifelse(rnorm(100,0,1)<0,"low","high") | |
# fitted = ifelse(rnorm(100,1,5)<0,"low","high") | |
# updateCM(table(actual,fitted)) |
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
# | |
# 4 constructor functions are included and they create S3 objects of the CART model | |
# by the rpart, caret and mlr packages - the last two extends the first. They are | |
# | |
# - cartRPART() | |
# - cartCARET() | |
# - cartMLR() | |
# - cartDT() | |
# | |
# Both classification and regression are supported. Together with the relevant packages, |
OlderNewer