This works fine:
mtcars %>%
group_by(cyl) %>%
summarize(r.sq = summary(lm(mpg ~ wt))$r.squared)
The problem here is not having to learn new paradigms just to do it, it's that you can't easily save intermediate steps because summarize wants the right hand side to be a vector, not a model object.
For example, the following code errors:
mtcars %>%
group_by(cyl) %>%
summarize(m = lm(mpg ~ wt))
And to get it to work, you have to start dealing with list-columns, which is a whole thing:
#this works, but makes a data frame with a list-column
mtcars %>%
group_by(cyl) %>%
summarize(m = list(lm(mpg ~ wt)))
TidyverseSkeptic/README.md
Line 641 in a8ad4dd
This works fine:
The problem here is not having to learn new paradigms just to do it, it's that you can't easily save intermediate steps because summarize wants the right hand side to be a vector, not a model object.
For example, the following code errors:
And to get it to work, you have to start dealing with list-columns, which is a whole thing: