View source: R/other_functions.R
spread_list | R Documentation |
Spread an existing list column into new columns on a data.frame. Note
that every element on every observation must have a name for the function
to do its work. Original column will be automatically suppressed but you
can set the replace
argument to avoid it.
spread_list(df, col, str = NULL, replace = TRUE)
df |
Dataframe |
col |
Variable name. |
str |
Character. Start column names with. If set to |
replace |
Boolean. Replace original values (delete column) |
data.frame. Result of un-nesting named or un-named list columns.
df <- dplyr::starwars
# Un-named list columns
spread_list(df, films, replace = FALSE) %>%
dplyr::select(name, dplyr::starts_with("films")) %>%
head(8)
# Named (and un-nammed) list columns
df <- dplyr::tibble(id = 1:3, platform = list(
list("fb" = 1, "ig" = 2),
list("fb" = 3),
list()
))
spread_list(df, platform, str = "ptf_")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.