map_chr()
在這個練習中,你會更進一步認識不同的 map_*() 變體。map() 函式的輸出永遠是清單(list)。map_*() 則會輸出其他型別。請先看下面的表格,確認每個 map_*() 變體各自的輸出型別。
map_*() |
Output |
|---|---|
map_chr() |
字元向量(character vector) |
map_lgl() |
邏輯向量(logical vector,值為 TRUE 或 FALSE) |
map_int() |
整數向量(integer vector) |
map_dbl() |
倍精度數值向量(double vector) |
本練習屬於課程
使用 purrr 的函式式程式設計基礎
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Pull out the director element of sw_films in a list and character vector
map(___, ~.x[["___"]])
map_chr(___, ~.x[["___"]])