8.2 MapReduce

高阶函数,简单来说,就是参数为函数,返回值也是函数。Base R 提供了 ReduceFilterFindMapNegatePosition 等常用函数,此外还有 *apply 族。

purrr::map 比较

在 R 语言里玩转applyMap()Reduce()21,下面分别以提取合并多张 XLSX 表格22,分组计算23 和子集操作 24 为例,从函数式编程到 MapReduce 25,制作数据透视表26,用于数据处理的函数式编程和单元测试 Functional programming and unit testing for data munging with R 特别是第三章 https://b-rodrigues.github.io/fput/,然后是函数式编程与数据建模 Modeling data with functional programming in R27

add <- function(x) Reduce("+", x)
add(list(1, 2, 3))
## [1] 6
add_accuml <- function(x) Reduce("+", x, accumulate = TRUE)
add_accuml(list(1, 2, 3))
## [1] 1 3 6