Sorry I am quite new to R, but I have a dataframe with gamelogs for multiple players. I am trying to get the slope coefficient for each player\'s points over all of their games.
You can also do some magic with the base lm to do it all at once:
coef(lm(game ~ pts*name - pts, data=gamelogs))[3:4]
coef(lm(game ~ pts:name + name, data=gamelogs))[3:4]
#pts:nameplayer1 pts:nameplayer2
# -0.42857143 0.08241758
As a data.frame:
data.frame(slope=coef(lm(game ~ pts*name - pts, data=gamelogs))[3:4])
# slope
#pts:nameplayer1 -0.42857143
#pts:nameplayer2 0.08241758
See here for some further explanation of the modelling in the lm call:
https://stat.ethz.ch/R-manual/R-devel/library/stats/html/formula.html
http://faculty.chicagobooth.edu/richard.hahn/teaching/FormulaNotation.pdf#2
In this case pts*name expands to pts + name + pts:name which when removing - pts means it is equivalent to pts:name + name