R code for baseball analytics