Congratulations!

Reshaping Data with tidyr

Jeroen Boeye

Head of Machine Learning, Faktion

Separating messy string columns

separate()

Column with multiple variables

One column per variable

separate_rows()

Cell with multiple values

One value per cell

Reshaping Data with tidyr

Pivoting data

pivot_longer()

Variables as headers

Variables as headers tidy

pivot_wider()

Variable names in column

Variable names in column fixed

Reshaping Data with tidyr

Expanding data

complete()

Before complete

 

After complete with fill

Reshaping Data with tidyr

Unnesting data

tibble(character = star_wars_list) %>% 
  unnest_wider(character) %>% 
  unnest_longer(films)
# A tibble: 45 x 2
   name        films                  
   <chr>       <chr>                  
 1 Chewbacca   Revenge of the Sith    
 2 Chewbacca   Return of the Jedi     
 3 Chewbacca   The Empire Strikes Back
 4 Chewbacca   A New Hope             
 5 Chewbacca   The Force Awakens      
 6 Darth Vader Revenge of the Sith    
 7 Darth Vader Return of the Jedi     
 8 Darth Vader The Empire Strikes Back
# ... with 37 more rows
Reshaping Data with tidyr

The end

Reshaping Data with tidyr

Preparing Video For Download...