x <- list(1, 1, 1)
y <- list(10, 20, 30)
map2(x, y, \(x, y) x + y)
# Or just
map2(x, y, `+`)
# Split into pieces, fit model to each piece, then predict
by_cyl <- mtcars |> split(mtcars$cyl)
mods <- by_cyl |> map(\(df) lm(mpg ~ wt, data = df))
map2(mods, by_cyl, predict)
Run the code above in your browser using DataLab