Last time around I used R to plot the average runs per game for the American League, starting in 1901. Now I’ll do the same for the National League. I'll save a comparison of the two leagues for my next post.
A fundamental principal of programming is that code can be repurposed for different sets of datas. So much of what I’m going to describe recycles the R code I used for the AL exercise.
So starting with the preliminary step, I went back to Baseball Reference for the data, followed up by the same sort of finessing described for the AL. Once the data was read into the R workspace, I simply copies the AL code, and changed the variable names to create new objects and variables. (I could have simply rerun the same code, but I wanted to have both the AL and NL data and trend lines available for comparison.) This included creating new LOESS trend lines.