R/tidy.R
map2_cog.Rd
Map over multiple inputs simultaneously and return a vector of cognostics data frames
map2_cog(.x, .y, .f, ...) pmap_cog(.l, .f, ...)
.x, .y | Vectors of the same length. A vector of length 1 will be recycled. |
---|---|
.f | A function, formula, or atomic vector (see |
... | additional arguments passed on to .f. |
.l | A list of lists. The length of .l determines the number of arguments that .f will be called with. List names will be used if present. |
See map2
# \donttest{ library(tidyr) library(purrr) library(plotly) library(dplyr) iris %>% nest(data = -Species) %>% mutate( mod = map(data, ~ lm(Sepal.Length ~ Sepal.Width, data = .x)), cogs = map2_cog(data, mod, function(data, mod) { tibble(max_sl = max(data$Sepal.Length), slope = coef(mod)[2]) }), panel = map2_plot(data, mod, function(data, mod) { plot_ly(data = data, x = ~Sepal.Width, y = ~Sepal.Length, type = "scatter", mode = "markers", name = "data") %>% add_trace(data = data, x = ~Sepal.Width, y = ~predict(mod), mode = "lines", name = "lm") })) %>% trelliscope(name = "iris") # }