且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何直接在 purrr::accumulate2() 中编写自定义函数

更新时间:2022-03-25 09:18:31

.x.y 仅在有两个参数时指定.如果超过 2 个,我们可以按出现顺序使用 ..1, ..2, ..3

The .x and .y are only specified when there are two arguments. With more than 2, we can use ..1, ..2, ..3 in their order of occurrence

library(purrr)
accumulate2(1:5, 1:4, ~2*..1 + 3*..2 +..3)
#[[1]]
#[1] 1

#[[2]]
#[1] 9

#[[3]]
#[1] 29

#[[4]]
#[1] 73

#[[5]]
#[1] 165