【问题标题】:Recursively apply functions on vector with purrr用 purrr 递归地在向量上应用函数
【发布时间】:2019-07-12 18:35:09
【问题描述】:

有人可以告诉我这是什么版本的 purrr:

fl <- list(sin, cos, cos, sqrt)
x <- seq(0, 1, length.out = 10)
Reduce(function(f, ...) f(...), fl, x, right = T)

(我尝试reduce和accumulate都没有成功。)

【问题讨论】:

    标签: r purrr


    【解决方案1】:
    library(purrr)
    
    lift(compose)(fl)(x)
    #>  [1] 0.5143953 0.5528477 0.5880842 0.6202147 0.6493739 0.6757146 0.6994011
    #>  [8] 0.7206037 0.7394947 0.7562439
    

    reprex package (v0.2.1) 于 2019-02-19 创建

    或者

    compose(!!! fl)(x)
    

    【讨论】:

    • 谢谢。第二个选项的引用 (!!!) 不起作用。有办法解决吗?
    • 我的 purrr 版本是 0.3.0。哪个是你的?
    猜你喜欢
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-19
    相关资源
    最近更新 更多