openintro (version 2.0.0)

mlbbat10: Major League Baseball Player Hitting Statistics for 2010

Description

Major League Baseball Player Hitting Statistics for 2010.

Usage

mlbbat10

Arguments

Format

A data frame with 1199 observations on the following 19 variables.

name

Player name

team

Team abbreviation

position

Player position

game

Number of games

at_bat

Number of at bats

run

Number of runs

hit

Number of hits

double

Number of doubles

triple

Number of triples

home_run

Number of home runs

rbi

Number of runs batted in

total_base

Total bases, computed as 3*HR + 2*3B + 1*2B + H

walk

Number of walks

strike_out

Number of strikeouts

stolen_base

Number of stolen bases

caught_stealing

Number of times caught stealing

obp

On base percentage

slg

Slugging percentage (total_base / at_bat)

bat_avg

Batting average

Examples

Run this code
# NOT RUN {
d   <- mlbbat10[mlbbat10$at_bat > 200,]
pos <- list(c("OF"), c("1B", "2B", "3B", "SS"), "DH", "C")
POS <- c("OF", "IF", "DH", "C")

#=====> On-base Percentage Across Positions <=====#
out <- c()
gp  <- c()
for(i in 1:length(pos)){
	these <- which(d$position %in% pos[[i]])
	out   <- c(out, d[these, "obp"])
	gp    <- c(gp, rep(POS[i], length(these)))
}
plot(out ~ as.factor(gp))
summary(lm(out ~ as.factor(gp)))
anova(lm(out ~ as.factor(gp)))

#=====> Batting Average Across Positions <=====#
out <- c()
gp  <- c()
for(i in 1:length(pos)){
	these <- which(d$pos %in% pos[[i]])
	out   <- c(out, d[these,"AVG"])
	gp    <- c(gp, rep(POS[i], length(these)))
}
plot(out ~ as.factor(gp))
summary(lm(out ~ as.factor(gp)))
anova(lm(out ~ as.factor(gp)))

#=====> Home Runs Across Positions <=====#
out <- c()
gp  <- c()
for(i in 1:length(pos)){
	these <- which(d$pos %in% pos[[i]])
	out   <- c(out, d[these,"HR"])
	gp    <- c(gp, rep(POS[i], length(these)))
}
plot(out ~ as.factor(gp))
summary(lm(out ~ as.factor(gp)))
anova(lm(out ~ as.factor(gp)))

#=====> Runs Batted In Across Positions <=====#
out <- c()
gp  <- c()
for(i in 1:length(pos)){
	these <- which(d$pos %in% pos[[i]])
	out   <- c(out, d[these,"RBI"])
	gp    <- c(gp, rep(POS[i], length(these)))
}
plot(out ~ as.factor(gp))
summary(lm(out ~ as.factor(gp)))
anova(lm(out ~ as.factor(gp)))
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace