Function Composition in R (and high level functions)

后端 未结 3 952
执笔经年
执笔经年 2021-02-19 01:28

Is there something like a function composition in R?

I think in haskell it\'s somthing like \"(.)\" and in agda it\'s the ring operator.

Also, I find litte infor

3条回答
  •  灰色年华
    2021-02-19 02:00

    There is now a compose function in the purrr library. By default composition is made from right to left, as in Haskell, but it can be reversed with the .dir param:

    library(purrr)
    f = function(x) x+1
    g = function(x) x*3
    
    > compose(g,f)(1)
    [1] 6
    > compose(f,g, .dir="forward")(1)
    [1] 6
    

提交回复
热议问题