## Let's calculate Mike Trout's OBP for the 2014 season
## He had 173 hits, 83 bases on balls, 10 hit by pitches, 602 at bats, and 10 sacrifice flies
## We should get 0.377 as our output
obp(173,83,10,602,10)
## The function is currently defined as
function (H, BB, HBP, AB, SF)
{
onbase <- ((H + BB + HBP)/(AB + BB + SF + HBP))
return(onbase)
}
Run the code above in your browser using DataLab