操作 URL

使用 purrr 的 R 語言中級函式程式設計

Colin Fay

Data Scientist & R Hacker at ThinkR

建立 mapper

as_mapper()

library(purrr)
mult <- as_mapper(~ .x * 2)
map(list(airquality, mtcars), 
    mult)
[[1]]
    Ozone Solar.R Wind Temp Month Day
1      82     380 14.8  134    10   2
2      72     236 16.0  144    10   4
3      24     298 25.2  148    10   6
4      36     626 23.0  124    10   8
5      NA      NA 28.6  112    10  10
6      56      NA 29.8  132    10  12
... 
使用 purrr 的 R 語言中級函式程式設計

stringr::str_detect()

樣式偵測:

library(stringr)
lyrics <- c("Is this the real life?", 
            "Is this just fantasy?", 
            "Caught in a landslide", 
            "No escape from reality")
str_detect(lyrics, "life")
TRUE FALSE FALSE FALSE
使用 purrr 的 R 語言中級函式程式設計

補充:邏輯值

邏輯值加總:

sum(FALSE, TRUE, TRUE, FALSE, TRUE)
3
使用 purrr 的 R 語言中級函式程式設計

一起來練習吧!

使用 purrr 的 R 語言中級函式程式設計

Preparing Video For Download...