O'Reilly logo

Baseball Hacks by Joseph Adler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Measure Batting with On-Base Percentage

Use on-base percentage as a simple measurement of a player’s offensive contributions.

Batting average is easy to calculate, but its meaning is actually kind of complicated. It ignores important offensive contributions (walks) and it doesn’t count sacrifices. Many baseball fans think that another statistic, on-base percentage (OBP), is a much better representation of hitting ability.

OBP is a measure of how many times a player makes it on base, whether he makes it on base through a hit (H), is awarded a walk (a base on balls, or BB), or is hit by a pitch (HBP). For batting average, we exclude walks, hits by pitches, and sacrifice flies (SF), but for OBP, we include all of these. The formula for OBP is a little more complicated than the formula for batting average:

	OBP = (H + BB + HBP) / (AB + BB + HBP + SF)

However, I think its meaning is clearer. There are no caveats; it’s just the percentage of time the player reaches base.

Sample Code

Here’s the simple way to calculate OBP, if you have already loaded the Baseball Archive data into R:

	attach(batting)
	batting$OBP <- (H + BB + HBP) / (AB + BB + HBP + SF)

As I explain in “Measure Batting with Batting Average” [Hack #40] , I use a slightly more difficult method of calculation. Basically, I calculate the average number of games a player’s teams played (when the player played on more than one team), and the total statistics for a player for a whole season. This lets me correctly calculate statistics ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required