इंटरमीडिएट फ़ंक्शनल प्रोग्रामिंग विथ purrr
Colin Fay
Data Scientist & R Hacker at ThinkR
एक function:
एक संख्या $n$:
एक character vector $z$
जब function हो, तो .f हो सकता है:
my_fun <- function(x) {
round(mean(x))
}
map_dbl(visit_2014, my_fun)
[1] 5526 6546 6097 7760
[5] 7025 7162 10484 8256
[9] 6558 7686 5723 5053
map_dbl(visit_2014, function(x) {
round(mean(x))
})
[1] 5526 6546 6097 7760
[5] 7025 7162 10484 8256
[9] 6558 7686 5723 5053
mapper: one-sided formula से anonymous function
# एक parameter के साथ
map_dbl(visits2017, ~ round(mean(.x)))
# इसके समकक्ष
map_dbl(visits2017, ~ round(mean(.)))
# इसके समकक्ष
map_dbl(visits2017, ~ round(mean(..1)))
mapper: one-sided formula से anonymous function
# दो parameters के साथ
map2(visits2016, visits2017, ~ .x + .y)
# इसके समकक्ष
map2(visits2016, visits2017, ~ ..1 + ..2)
# दो से अधिक parameters के साथ
pmap(list, ~ ..1 + ..2 + ..3)
as_mapper(): lambda function से mapper objects बनाएँ
# Classical function
round_mean <- function(x){
round(mean(x))
}
# Mapper के रूप में
round_mean <- as_mapper(~ round(mean(.x))))
Mappers होते हैं:
संक्षिप्त
पढ़ने में आसान
पुन:उपयोग योग्य

इंटरमीडिएट फ़ंक्शनल प्रोग्रामिंग विथ purrr