purrr ile Orta Düzey Fonksiyonel Programlama
Colin Fay
Data Scientist & R Hacker at ThinkR
rstudioconf: 5055 tweetten oluşan bir liste
length(rstudioconf)length(rstudioconf[[1]])
505531
library(purrr)
vec_depth(rstudioconf)
4
Kaynak: ThinkR-open/datasets
JSON == iç içe listeler
{
"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{ "value": "New", "onclick": "CreateNewDoc" },
{ "value": "Open", "onclick": "OpenDoc" },
{ "value": "Close", "onclick": "CloseDoc" }
]
}
}
}
Gördük:
map_*()
discard()
keep()
Yordayıcı işlevciller:
Koşulu sağlayan öğeleri keep() ile tutun:
keep(1:10, ~ .x < 5)
1 2 3 4
Koşulu sağlayan öğeleri discard() ile eler:
discard(1:10, ~ .x < 5)
5 6 7 8 9 10
purrr ile Orta Düzey Fonksiyonel Programlama