The following works fine:
library(dplyr)
m <- function(df) {
mod <- lm(Sepal.Length ~ Sepal.Width, data = df)
pred <- predict(mod,newdata = df[
You don't need an anonymous function:
library(dplyr)
iris %>%
group_by(Species) %>%
do({
mod <- lm(Sepal.Length ~ Sepal.Width, data = .)
pred <- predict(mod, newdata = .["Sepal.Width"])
data.frame(., pred)
})
You can't get rid of the .
.
iris %>%
group_by(Species) %>%
do((function(df) {
mod <- lm(Sepal.Length ~ Sepal.Width, data = df)
pred <- predict(mod,newdata = df["Sepal.Width"])
data.frame(df,pred)
})(.))
That will work. The .
is necessary. The .
is love. Keep the .
.