Learn R Programming

Sabermetrics (version 2.0)

slg: Slugging Percentage

Description

Slugging percentage is a measure of a hitter's power.

Usage

slg(TB, AB)

Arguments

TB
Total Bases
AB
At Bats

Value

Returns a numerical value equal to (TB/AB)This is also equivalent to ((singles) + (2 x doubles) + (3 x triples) + (4 x homeruns))/(AB)

References

https://en.wikipedia.org/wiki/Slugging_percentage

See Also

opsplus, ops

Examples

Run this code
## Let's calculate Mike Trout's SLG for the 2014 season
## He had 338 TB's and 602 AB's
## We should get .561 as our output
slg(338,602)

## The function is currently defined as
function (TB, AB) 
{
    slugging <- (TB/AB)
    return(slugging)
  }

Run the code above in your browser using DataLab