do
allows you to do work on a group at a time
Edit: as you said do
is superseded, and this is the more straight-forward (and encouraged) way of doing it. (The issue I had trying this before my do
answer was I was missing the use of cur_data()
.)
colnms <- names(iris)[2:4]
colnms
# [1] "Sepal.Width" "Petal.Length" "Petal.Width"
iris %>%
group_by(Species) %>%
summarize(
other = colnms,
mdl = map(colnms, ~ loess(as.formula(paste("Sepal.Length ~", .x)),
data = cur_data()))
)
# Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, :
# pseudoinverse used at 0.0975
# Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, :
# neighborhood radius 0.2025
# Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, :
# reciprocal condition number 2.8298e-016
# Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric, :
# There are other near singularities as well. 0.01
# # A tibble: 9 x 3
# # Groups: Species [3]
# Species other mdl
# <fct> <chr> <list>
# 1 setosa Sepal.Width <loess>
# 2 setosa Petal.Length <loess>
# 3 setosa Petal.Width <loess>
# 4 versicolor Sepal.Width <loess>
# 5 versicolor Petal.Length <loess>
# 6 versicolor Petal.Width <loess>
# 7 virginica Sepal.Width <loess>
# 8 virginica Petal.Length <loess>
# 9 virginica Petal.Width <loess>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…