openintro (version 1.7.1)

mlbBat10: Major League Baseball Player Hitting Statistics for 2010

Description

Major League Baseball Player Hitting Statistics for 2010.

Usage

data(mlbBat10)

Arguments

Format

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

name

Player name

team

Team abbreviation

position

Player position

G

Number of games

AB

Number of at bats

R

Number of runs

H

Number of hits

2B

Number of doubles

3B

Number of triples

HR

Number of home runs

RBI

Number of runs batted in

TB

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

BB

Number of walks

SO

Number of strikeouts

SB

Number of stolen bases

CS

Number of times caught stealing

OBP

On base percentage

SLG

Slugging percentage (TB / AB)

AVG

Batting average

Examples

Run this code
# NOT RUN {
data(mlbBat10)
d   <- mlbBat10[mlbBat10$AB > 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$pos %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)))

# }

Run the code above in your browser using DataCamp Workspace