## Let's calculate Mike Trout's 2014 wOBA
## He had 602 AB's, 83 BB's, 6 IBB's, 10 HBP's,
## 89 singles, 39 doubles, 9 triples, 36 homeruns, and 10 sac-flies
## We should get .408 as our output
woba(2014,602,83,6,10,89,39,9,36,10)
## The function is currently defined as
function (year, AB, BB, IBB, HBP, single, double, triple, HR,
SF)
{
wBB <- linearWeights$wBB[which(weights$Season == year)]
wHBP <- linearWeights$wHBP[which(weights$Season == year)]
w1B <- linearWeights$w1B[which(weights$Season == year)]
w2B <- linearWeights$w2B[which(weights$Season == year)]
w3B <- linearWeights$w3B[which(weights$Season == year)]
wHR <- linearWeights$wHR[which(weights$Season == year)]
woba <- ((wBB * BB) + (wHBP * HBP) + (w1B * single) + (w2B *
double) + (w3B * triple) + (wHR * HR))/(AB + BB - IBB +
SF + HBP)
return(woba)
}
Run the code above in your browser using DataLab