d <- subset(mlb_players_18, !position %in% c("P", "DH") & AB >= 100)
dim(d)
# _____ Per Position, No Further Grouping _____ #
plot(d$OBP ~ as.factor(d$position))
model <- lm(OBP ~ as.factor(position), d)
summary(model)
anova(model)
# _____ Simplified Analysis, Fewer Positions _____ #
pos <- list(
c("LF", "CF", "RF"),
c("1B", "2B", "3B", "SS"),
"C"
)
POS <- c("OF", "IF", "C")
table(d$position)
# _____ 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$OBP[these])
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 DataLab