I wonder if it is possible to use lm() within mutate() of dplyr package. Currently I have a dataframe of \"date\", \"company\", \"return\" and \"market.ret\" reproducible as
This seems to work for me:
group_by(x, company) %>% do(data.frame(beta = coef(lm(return ~ market.ret,data = .))[2])) %>% left_join(x,.)