Applying over a vector of functions

后端 未结 2 1585
野性不改
野性不改 2020-12-16 17:52

Given a vector (actually a list) of functions:

 fs = c(sin, cos, tan)

and a vector of values:

 xs = c(.1, .3, .5)
         


        
2条回答
  •  暖寄归人
    2020-12-16 18:41

    Here's an alternative whose main advantage over the suggestions so far is that it doesn't require that an anonymous function be defined.

    mapply(do.call, fs, lapply(xs, list))
    # [1] 0.09983342 0.95533649 0.54630249
    

提交回复
热议问题