本文介绍了R中的功能组合(以及高级功能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R中是否有类似函数组合的东西?

Is there something like a function composition in R?

我认为在haskell中,它就像(.)"之类,而在agda中,它是ring操作符.

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

此外,我在R中找到了有关高级功能编程的信息.我发现了功能减少",地图",过滤器" ...,还有更多功能吗?有指针吗?

Also, I find litte information on high level functional programming in R.I found the Functions "Reduce", "Map", "Filter"..., are there more? Any pointers?

推荐答案

您可以使合成功能如下:

You may make compositing function like this:

composite<-function(f,g) function(...) f(g(...))

f<-function(x) x+1;
g<-function(x) x*2;
composite(f,g)(7)
composite(g,f)(7)

或对此进行操作.

关于第二点,有很多这样的观点;我认为使用最多的是* apply系列(apply,mapply,tapply,lapply,apply ...).

About the second point, there are lots of such; I think the most used are the *apply family (sapply, mapply, tapply, lapply, apply...).

这篇关于R中的功能组合(以及高级功能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 20:20