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
one_lm_attempt <- function (df, target) { | |
rnd5 <- sample(10,5) | |
predictor_variables <- names(df)[rnd5] | |
#create the formula, string to give to lm() | |
rnd_formula <- formula(paste(target, " ~ ", | |
paste(predictor_variables, collapse=" + "))) | |
m <- lm(rnd_formula, df) | |
#print (summary(m)$r.squared) | |
#print (summary(m)$adj.r.squared) | |
return(c(rnd5, summary(m)$r.squared,summary(m)$adj.r.squared )) |
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(ggplot2) | |
head(diamonds,10) | |
colList <- c("cut", "clarity") #list of columns to replace. Can also be column numbers. | |
rowstoReplace <- 1:10 | |
lapply(colList, function(colname){gsub("I", ".", diamonds[rowstoReplace, colname])}) | |
#lapply gives it one column name at a time... | |
#Use a comma instead of rowstoReplace if you want all rows changed. | |
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(shiny) | |
updates <- 0 | |
updater <- function(updates){ updates + 1 } | |
shinyServer(function(input,output, session){ | |
updateTracker <- reactive( { | |
invalidateLater(as.numeric(input$secPause) * 1000, session) |
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
rm(list=ls()) | |
library(ggplot2) | |
df <- read.csv("~/RStats/data/ResearchGrants2013.csv", stringsAsFactors=F, strip.white=T) | |
df <- df[,-6] #get rid of the trailing blank | |
dim(df) | |
#quick check | |
unique(df$Research.Category) | |
table(df$Research.Category) |
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
# @ Given a data frame slice, this function determines who had more wins in that slice | |
moreWins <- function(df) { | |
valid.rows <- sum(!is.na(df$GK.won)) # count of 0 or 1 values | |
if(valid.rows==0) { | |
return("00") | |
} | |
gk.wins <- sum(na.omit(df$GK.won == "1")) #how many times did GK win | |
gk.losses <- sum(na.omit(df$GK.won == "0")) #how many times did GK lose | |
if(gk.wins > gk.losses) { |
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
rm(list=ls()) | |
library(ggplot2) | |
library(plyr) | |
library(reshape2) | |
df <- read.csv("~/RStats/data/KvsK_lifetime.csv", stringsAsFactors=F, strip.white=T) | |
df <- arrange(df, game) #use plyr's arrange to Sort by Game Number | |
#For ease drop the Opening, Event.Locale columns and Moves Columns |
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(lpSolveAPI) | |
library(reshape2) | |
library(ggplot2) | |
#Problem definition | |
trim.lengths <- c(44, 57, 86, 86, 40, 88, 88, 41, 40, 40, 62, 62, 54, 54, 55, 55, 63, 63, 75, 75, 100, 100) | |
avail.lengths <- c(120, 103, rep(100, 9), 98, rep(97, 4), 95, rep(88, 3), 85, 65) | |
num.trims = length(trim_lengths) #22 | |
num.avail = length(avail.lengths) #22 |
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
init(side, num.colors) #df, const.type.vec have been initialized | |
df <- populate.Amatrix() #see github link for this function | |
rhs.vector <- create_rhs_vector(rhs.vector, terminal.cells) | |
const.type.vec <- createConstraintTypeVector(const.type.vec) | |
length(rhs.vector); length(const.type.vec) | |
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
terminal.cells <- read.csv(problemfile, header=T, stringsAsFactors=FALSE) | |
terminal.cells$tcell <- (terminal.cells$Y -1)* side + terminal.cells$X # cell serial number | |
num.colors <- length(unique(terminal.cells$color)) | |
colorpalette <- unique(terminal.cells$palette) | |
#The problemfile | |
#X,Y,color, palette | |
#1,5,1,red | |
#2,4,1,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
# actual problem definition | |
lpff <- make.lp(nrow=n.row, ncol=n.col) | |
defineIP() | |
lpff | |
solve(lpff) | |
sol <- get.variables(lpff) | |
defineIP <- function() { |