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
# 分類用 | |
types <- c("A","B","C","D","E") | |
# 行数 | |
obs <- 4e+06 | |
# データフレームの作成 | |
dat <- data.frame(type = as.factor(sample(types, obs, replace=TRUE))) | |
# 列数を増やしながら時間を計測していく | |
Nmax <- 10 | |
plyr_time <- 0 |
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
# 参考文献: | |
# http://d.hatena.ne.jp/dichika/20140103/p1 | |
library(devtools) | |
#install_github("dplyr") # うまくいかない | |
library(plyr) | |
library(doBy) | |
library(reshape2) | |
library(ggplot2) | |
set.seed(42) |
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(plyr) | |
library(MASS) | |
# データの読み込み | |
data2011 <- read.csv("all2011.csv") | |
fields <- read.csv("fields.csv") | |
names(data2011) <- fields[,"Header"] | |
# 01データで, 1の連の長さを数える |
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(ggplot2) | |
library(lattice) | |
library(pitchRx) | |
library(plyr) | |
dat0402 <- scrapeFX(start="2013-04-02", end="2013-04-02") | |
pitches0402 <- plyr::join(dat0402$pitch, dat0402$atbat, | |
by = c("num", "url"), | |
type="inner") | |
iwakuma0402 <- subset(pitches0402, pitcher_name=="Hisashi Iwakuma") |
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(plyr) | |
# データ読み込み | |
data2013 <- read.csv("all2013.csv") | |
fields <- read.csv("fields.csv") | |
names(data2013) <- fields[,"Header"] | |
# 打者結果だけ | |
data2013 <- subset(data2013, BAT_EVENT_FL == TRUE) | |
# 大チャンス場面かどうかをSuperChanceに入れる |
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
# データ読み込み | |
Pitching <- read.csv("Pitching.csv") | |
# 重いので2000年以降に限る | |
Pitching <- subset(Pitching, yearID> 2000) | |
# plyrを使ってデータを要約 | |
Pitching.KBB <- ddply(Pitching, .(playerID), summarize, | |
Career.SO = sum(SO, na.rm = TRUE), Career.BB = sum(BB, na.rm=TRUE), | |
Career.IPouts = sum(IPouts, na.rm = 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
# install.packages(c("Rcpp", "inline")) | |
library(Rcpp) | |
library(inline) | |
# sort_stl | |
src <- " | |
NumericVector x(xx); | |
std::sort(x.begin(), x.end()); | |
return x; | |
" | |
stlsort <- cxxfunction(signature(xx="numeric"), src, plugin = "Rcpp") |
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
# R vs Cpp (sorting) | |
library(Rcpp) | |
library(inline) | |
library(ggplot2) | |
library(reshape2) | |
# sort_stl | |
src <- " | |
NumericVector x(xx); | |
std::sort(x.begin(), x.end()); |
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(pitchRx) | |
library(chron) | |
library(doBy) | |
library(plyr) | |
library(ggplot2) | |
#data2013 <- scrapeFX(start="2013-02-01", end="2013-10-01") | |
data2013 <- read.csv("2013.csv") | |
#data2013 <- subset(data2013, sv_id != "NA") |
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(ggplot2) | |
x <- seq(0,10, by = 0.1) | |
y <- sin(x) | |
z <- sin(x) + 1 | |
xyz <- data.frame(x=x, y=y,z=z) | |
p <- ggplot() | |
p <- p + geom_line(data = xyz, aes(x = x, y=y)) + geom_line(data = xyz, aes(x=x, y=z)) |
OlderNewer