8.2 MapReduce
高阶函数,简单来说,就是参数为函数,返回值也是函数。Base R 提供了 Reduce
、Filter
、Find
、Map
、Negate
和 Position
等常用函数,此外还有 *apply
族。
与 purrr::map
比较
在 R 语言里玩转apply
, Map()
和 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
<- function(x) Reduce("+", x)
add add(list(1, 2, 3))
## [1] 6
<- function(x) Reduce("+", x, accumulate = TRUE)
add_accuml add_accuml(list(1, 2, 3))
## [1] 1 3 6
https://stackoverflow.com/questions/3505701/grouping-functions-tapply-by-aggregate-and-the-apply-family↩︎
https://trinkerrstuff.wordpress.com/2018/02/14/easily-make-multi-tabbed-xlsx-files-with-openxlsx/↩︎
https://statcompute.wordpress.com/2018/09/03/playing-map-and-reduce-in-r-by-group-calculation/↩︎
https://statcompute.wordpress.com/2018/09/08/playing-map-and-reduce-in-r-subsetting/↩︎
https://cartesianfaith.com/2015/09/17/from-functional-programming-to-mapreduce-in-r/↩︎
https://digitheadslabnotebook.blogspot.com/2010/01/pivot-tables-in-r.html↩︎
https://cartesianfaith.files.wordpress.com/2015/12/rowe-modeling-data-with-functional-programming-in-r.pdf↩︎