Jenny Bryan’s Lego-themed glamour shots illustrating R Data Structures

Code Example: List to Data Frame

 

The following code example illustrates how to take a list column inside a data frame and wrangle it – making it easier to analyze. For more information, see the HTML output. for the R Notebook, list_to_dataframe.Rmd.

Date

2018-02-06

Example Code, Abbreviated

library(tidyverse)
library(repurrrsive)

dataframe_list <- tibble(
  name = map_chr(got_chars, "name"),
  title = map(got_chars, "titles")
)

dataframe_list %>% 
  mutate(n_titles = map_int(title, length)) %>% 
  filter(n_titles > 1) %>% 
  select(name, title) %>% 
  unnest()

References

This example comes from a Jenny Bryan Workshop, What they forgot to teach you about R. Similar examples can be found in Bryan’s Purrr tutorial. Specifically…

Image Credit:

https://github.com/jennybc/lego-rstats