r - Reducing data frame by linear regression -


i reduce following data frame:

subject, run, condition, dv 1, 1, 1, 123 1, 1, 2, 456 1, 1, 3, 789 1, 2, 1, 123 1, 2, 2, 456 1, 2, 3, 789 2, 1, 1, 123 2, 1, 2, 456 2, 1, 3, 789 2, 2, 1, 123 2, 2, 2, 456 2, 2, 3, 789 

to data frame:

subject, run, coeff(lm(dv ~ condition)) 1, 1, ??? 1, 2, ??? 2, 1, ??? 2, 2, ??? 

any ideas on how approach this?

you should use do rather summarize:

df %>% group_by(subject, run) %>%   do(lm = lm(dv ~ condition,data=.)) %>%    summarize(subject=subject,             run=run,             coef=coef(lm)[[2]]) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

authentication - Mongodb revoke acccess to connect test database -

python - Scipy.Odr multiple variable regression -