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
df1 = data.frame(a = 1:3, b = 4:6, c = 7:9) | |
df2 = data.frame(c = 10:12, a = 13:15, b = 16:18) | |
merge(df1,df2, all=TRUE) | |
# a b c | |
# 1 1 4 7 | |
# 2 2 5 8 | |
# 3 3 6 9 | |
# 4 13 16 10 | |
# 5 14 17 11 |
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(Lahman) | |
library(dplyr) | |
library(magrittr) | |
library(pings) | |
# Batting: season stats data frame of all the players | |
all_dat <- Batting %>% | |
select(yearID, AB, H, HR) %>% | |
group_by(yearID) %>% | |
dplyr::summarise(H = sum(H, na.rm = 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
playerID | careerHit | careerHit.x | careerHit.y | fullname | |
---|---|---|---|---|---|
aaronha01 | 3771 | 3771 | 3771 | Hank Aaron | |
ansonca01 | 3418 | 3418 | 3418 | Cap Anson | |
biggicr01 | 3060 | 3060 | 3060 | Craig Biggio | |
boggswa01 | 3010 | 3010 | 3010 | Wade Boggs | |
brettge01 | 3154 | 3154 | 3154 | George Brett | |
brocklo01 | 3023 | 3023 | 3023 | Lou Brock | |
carewro01 | 3053 | 3053 | 3053 | Rod Carew | |
clemero01 | 3000 | 3000 | 3000 | Roberto Clemente | |
cobbty01 | 4189 | 4189 | 4189 | Ty Cobb |
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) | |
library(ggplot2) | |
library(kernlab) | |
library(dplyr) | |
library(magrittr) | |
shinyServer(function(input, output){ | |
output$distPlot = reactivePlot(function(){ | |
param = 10 ^ input$param | |
#package 'kernlab' = kernel pca |
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
d=data.frame(lt=c("blank", "solid", "dashed", "dotted", "dotdash", "longdash", "twodash", "1F", "F1", "4C88C488", "12345678")) | |
ggplot() + | |
scale_x_continuous(name="", limits=c(0,1), breaks=NA) + | |
scale_y_discrete(name="linetype") + | |
scale_linetype_identity() + | |
geom_segment(data=d, mapping=aes(x=0, xend=1, y=lt, yend=lt, linetype=lt)) |
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(dplyr) | |
library(magrittr) | |
library(data.table) | |
library(ggplot2) | |
# pitch f/x data 2013 | |
dat = fread("2013.csv") | |
dat = dat %>% filter(sv_id !="NA") | |
# hit event |
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(Rcpp) | |
library(inline) | |
cpp_code = " | |
using namespace Rcpp; | |
double piSugar(int N){ | |
RNGScope scope; | |
NumericVector x = runif(N); | |
NumericVector y = runif(N); | |
NumericVector d = sqrt(x*x + y*y); |
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(data.table) | |
library(dplyr) | |
library(stringr) | |
# read data | |
dat = fread("all2013.csv") | |
fields = fread("fields.csv") | |
setnames(dat, fields$Header) | |
# processing datatable |
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(data.table) | |
library(plyr) | |
library(dplyr) | |
master = fread("Master.csv") | |
master$fullname = with(master, paste(nameFirst, nameLast)) | |
name_id_data = with(master, data.frame(name = fullname, PIT_ID = retroID)) | |
season_babip <- function(year){ | |
filename = paste("all", year, ".csv", sep="") |
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(pitchRx) | |
library(ggplot2) | |
library(data.table) | |
library(dplyr) | |
# データ取得 | |
# data = scrapeFX("2013-01-01", "2013-10-01") | |
# 取得済みデータの利用 | |
# data <- fread("2013.csv") |