워크플로에서 purrr 활용하기

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"
purrr로 배우는 함수형 프로그래밍 기초

질문하면서 이름 설정하기

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"
purrr로 배우는 함수형 프로그래밍 기초

연습해 봅시다!

purrr로 배우는 함수형 프로그래밍 기초

Preparing Video For Download...