hoist | R Documentation |
hoist()
allows you to selectively pull components of a list-column
into their own top-level columns, using the same syntax as purrr::pluck()
.
Learn more in vignette("rectangle")
.
hoist(
.data,
.col,
...,
.remove = TRUE,
.simplify = TRUE,
.ptype = NULL,
.transform = NULL
)
.data |
A data frame. |
.col |
< |
... |
< The column names must be unique in a call to |
.remove |
If |
.simplify |
If |
.ptype |
Optionally, a named list of prototypes declaring the desired output type of each component. Alternatively, a single empty prototype can be supplied, which will be applied to all components. Use this argument if you want to check that each element has the type you expect when simplifying. If a |
.transform |
Optionally, a named list of transformation functions applied to each component. Alternatively, a single function can be supplied, which will be applied to all components. Use this argument if you want to transform or parse individual elements as they are extracted. When both |
Other rectangling:
unnest_longer()
,
unnest_wider()
,
unnest()
df <- tibble(
character = c("Toothless", "Dory"),
metadata = list(
list(
species = "dragon",
color = "black",
films = c(
"How to Train Your Dragon",
"How to Train Your Dragon 2",
"How to Train Your Dragon: The Hidden World"
)
),
list(
species = "blue tang",
color = "blue",
films = c("Finding Nemo", "Finding Dory")
)
)
)
df
# Extract only specified components
df %>% hoist(metadata,
"species",
first_film = list("films", 1L),
third_film = list("films", 3L)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.