Foundations of Functional Programming with purrr
Auriel Fournier
Instructor
library(repurrrsive)
data(sw_films)
names(sw_films)
NULL
str(sw_films)
List of 14
$ title : chr ...
$ episode_id : int ...
$ opening_crawl: chr ...
$ director : chr ...
...
sw_films <- sw_films %>% set_names(map_chr(sw_films, "title"))
names(sw_films)
[1] "A New Hope"
[2] "Attack of the Clones"
[3] "The Phantom Menace"
[4] "Revenge of the Sith"
[5] "Return of the Jedi"
[6] "The Empire Strikes Back"
[7] "The Force Awakens"
map_chr(sw_films, ~.x[["episode_id"]]) %>%
set_names(map_chr(sw_films, "title")) %>%
sort()
The Phantom Menace Attack of the Clones
"1" "2"
Revenge of the Sith A New Hope
"3" "4"
The Empire Strikes Back Return of the Jedi
"5" "6"
The Force Awakens
"7"
Foundations of Functional Programming with purrr