flat_map_dfr()
calls map()
, and then row binds the results into a
data frame using vec_rbind()
.
flat_map_dfc()
calls map()
, and then column binds the results into a
data frame using vec_cbind()
.
flat_map_dfr(.x, .f, ..., .ptype = NULL, .names_to = NULL, .name_repair = c("unique", "universal", "check_unique")) flat_map_dfc(.x, .f, ..., .ptype = NULL, .size = NULL, .name_repair = c("unique", "universal", "check_unique", "minimal"))
.x | A list or atomic vector. |
---|---|
.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 |
... | Data frames or vectors.
|
.ptype | If Alternatively, you can supply |
.names_to | Optionally, the name of a column where the names
of |
.name_repair | One of With |
.size | If, Alternatively, specify the desired number of rows, and any inputs of length 1 will be recycled appropriately. |
flat_map_dfr()
and flat_map_dfc()
try a bit harder to coerce the results
of .f
to a data frame than flat_map_vec()
would. For example, if a result
of .f
is a 1d vector, for flat_map_dfr()
it would be coerced into a 1
row data frame with as many columns as number of elements in the vector.
#> x #> 1 1 #> 2 1 #> 3 1 #> 4 1 #> 5 1#>#> #> #> #> #>#> x...1 x...2 x...3 x...4 x...5 #> 1 1 1 1 1 1# `flat_map_dfr()` "tries harder" to coerce vectors to a data frame try(flat_map_vec(1:5, ~.x, .ptype = data.frame(x = integer())))#> Error : Can't cast <integer> to <data.frame<x:integer>>.flat_map_dfr(1:5, ~.x)#>#>#>#>#>#>#>#>#>#>#> ...1 #> 1 1 #> 2 2 #> 3 3 #> 4 4 #> 5 5