xmap | R Documentation |
These functions are variants of purrr::pmap()
that iterate over each
combination of elements in a list.
xmap(.l, .f, ...) xmap_chr(.l, .f, ...) xmap_dbl(.l, .f, ...) xmap_dfc(.l, .f, ...) xmap_dfr(.l, .f, ..., .id = NULL) xmap_int(.l, .f, ...) xmap_lgl(.l, .f, ...) xmap_raw(.l, .f, ...) xwalk(.l, .f, ...)
.l |
A list of vectors, such as a data frame. The length of .l determines the number of arguments that .f will be called with. List names will be used if present. |
.f |
A function, formula, or vector (not necessarily atomic). If a function, it is used as is. If a formula, e.g.
This syntax allows you to create very compact anonymous functions. If character vector, numeric vector, or list, it is
converted to an extractor function. Character vectors index by
name and numeric vectors index by position; use a list to index
by position and name at different levels. If a component is not
present, the value of |
... |
Additional arguments passed on to |
.id |
Either a string or Only applies to |
Typed variants return a vector of the specified type.
To automatically determine type, try xmap_vec()
.
To return results as a matrix or array, try xmap_mat()
and xmap_arr()
.
Note that a data frame is a very important special case, in which case
xmap()
and xwalk()
apply the function .f
to each row.
xmap_dfr()
and xmap_dfc()
return data frames created by row-binding and
column-binding respectively.
An atomic vector, list, or data frame, depending on the suffix. Atomic vectors and lists will be named if the first element of .l is named.
If all input is length 0, the output will be length 0. If any input is length 1, it will be recycled to the length of the longest.
xmap_vec()
to automatically determine output type.
xmap_mat()
and xmap_arr()
to return results in a matrix or array.
future_xmap()
to run xmap
functions with parallel processing.
cross_fit()
to apply multiple models to multiple subsets of data.
cross_list()
to find combinations of list elements.
purrr::map()
, purrr::map2()
, and purrr::pmap()
for other mapping
functions.
xmap(list(1:5, 1:5), ~ .y * .x) xmap_dbl(list(1:5, 1:5), ~ .y * .x) xmap_chr(list(1:5, 1:5), ~ paste(.y, "*", .x, "=", .y * .x)) apples_and_bananas <- list( x = c("apples", "bananas"), pattern = "a", replacement = c("oo", "ee") ) xmap_chr(apples_and_bananas, gsub) formulas <- list(mpg ~ wt, mpg ~ hp) subsets <- split(mtcars, mtcars$cyl) xmap(list(subsets, formulas), ~ lm(.y, data = .x)) xmap(list(data = subsets, formula = formulas), lm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.