Skip to Content
Baseball Hacks
book

Baseball Hacks

by Joseph Adler
January 2006
Beginner
467 pages
14h 21m
English
O'Reilly Media, Inc.
Content preview from Baseball Hacks

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. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

A Century of Mistakes in Baseball

A Century of Mistakes in Baseball

Martin B. Schmidt, David J. Berri
The Human Factor in AI-Based Decision-Making

The Human Factor in AI-Based Decision-Making

Philip Meissner, Christoph Keding
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 0596009429Errata Page