Learn R Programming

Sabermetrics (version 1.0)

obp: On-Base Percentage

Description

Function to calculate the on-base percentage of a player/team

Usage

obp(H, BB, HBP, AB, SF)

Arguments

H
Hits
BB
Unintentional Walks
HBP
Hit by pitch
AB
At bats
SF
Sacrifice flies

Value

  • Returns the following: ((H+BB+HBP)/(AB+BB+SF+HBP))

Details

On-base percentage is used to figure out how often an entity gets on-base

References

http://en.wikipedia.org/wiki/On-base_percentage

See Also

Slugging Percentage slg, OPS ops and Isolated Power iso

Examples

Run this code
## The on-base percentage (obp) function is currently defined as

function (H, BB, HBP, AB, SF) 
{
  onbase <- ((H+BB+HBP)/(AB+BB+SF+HBP))
  return(onbase)
}
  
## Let's take 2014's MLB MVP, Mike Trout, and find his on-base percentage
## Stats for Mike Trout available on
## http://www.baseball-reference.com/players/t/troutmi01-bat.shtml
## For 2014, Trout had 173 H, 83 BB, 10 HBP, 602 AB, 10 SF
## The formula for his on-base percentage using the obp function is below
## Output should be 0.377305
obp(173,83,10,602,10)

Run the code above in your browser using DataLab