## The equivalent average (eqa) function is currently defined as
function (H, TB, BB, HBP, SB, SAC, SF, AB, CS)
{
eqa <- (H + TB + 1.5 * (BB + HBP) + SB + SAC + SF)/(AB +
BB + HBP + SAC + SF + CS + (SB/3))
return(eqa)
}
## Let's take 2014's MLB MVP, Mike Trout, and find his OPS
## Stats for Mike Trout available on
## http://www.baseball-reference.com/players/t/troutmi01-bat.shtml
## For 2014, Trout had 173 H, 338 TB, 83 BB, 10 HBP, 16 SB, 0 SAC, 10 SF, 602 AB, 2 CS
## The formula for his EQA using the ops function is below
## Output should be .9496958
eqa(173,338,83,10,16,0,10,602,2)
Run the code above in your browser using DataLab