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