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 SLG

Use slugging average to measure batting power.

Slugging average (SLG) is a kind of weighted batting average. In normal batting average, all hits count the same, but in SLG, doubles count twice, triples count three times, and home runs count four times. A high SLG means that a hitter hits the ball often and hits it hard. SLG is an old statistic, but writers such as Bill James have made it much more popular recently.

On-base percentage histogram and box plot

Figure 5-2. On-base percentage histogram and box plot

The Formula

For convenience, we’ll use the expression total bases (TB) in this hack. Total bases is a weighted measurement of hits: singles count for 1, doubles count for 2, triples count for 3, and home runs count for 4. If you know how many hits (H), doubles (2B), triples (3B), and home runs (HR) a player hit, you can calculate TB:

	TB = 1 * singles + 2 * doubles + 3 * triples + 4 * home runs 
	= H + 2B + 2 * 3B + 3 * HR

Using TB, we can give a simple formula for SLG:

	SLG = TB / AB

Sample Code

Here is some sample code for slugging average. To calculate SLG, we’ll start by loading the Baseball Archive database. We’ll then use the same technique we use in “Measure Batting with Batting Average” [Hack #40] to calculate SLG:

	# assumes b_and_t data frame has been created
	attach(b_and_t)
	TB <- H + X2B + 2 * X3B + 3 * HR
	b_and_t$TB <- TB
	SLG <- TB / AB
	b_and_t$SLG <- SLG

Running the Hack

Summary 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