## Let's calculate Mike Trout's 2014 OPS+
## He had an OBP = .377 and a SLG = .561
## League OBP = .316 and League SLG = .404
## We should get 158.1652 as our output
opsplus(.377,.561,.316,.404)
## The function is currently defined as
function (obp, slg, lgOBP, lgSLG)
{
opsplus <- ((obp/lgOBP) + (slg/lgSLG) - 1) * 100
return(opsplus)
}
Run the code above in your browser using DataLab