F中的FoldLeft函数是否可用? [英] Is the FoldLeft function available in R?

查看:124
本文介绍了F中的FoldLeft函数是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否在R中实现了foldLeft函数(和foldRight?)。



该语言应该是相当的功能因此我认为应该有这样的事情,但我在文档中找不到它。



对我来说,foldLeft函数适用于列表,并且具有以下签名:

  foldLeft [B](z:B)(f:(B,A)=> B):B 

它应该返回以下结果:



如果列表是[a0,a1,...,an(a),...,a)如果列表是[a0,a1,...,an ]。

(我使用 Scala List API



有人知道这样的函数是否存在于R中?

解决方案

?Reduce。
用法
Reduce(f,x,init,right = FALSE,accumulate = FALSE)

I would like to know if there is an implementation of the foldLeft function (and foldRight?) in R.

The language is supposed to be "rather" functional oriented and hence I think there should be something like this, but I could not find it in the documentation.

To me, foldLeft function applies on a list and has the following signature:

foldLeft[B](z : B)(f : (B, A) => B) : B

It is supposed to return the following result:

f(... (f(f(z, a0), a1) ...), an) if the list is [a0, a1, ..., an].

(I use the definition of the Scala List API)

Does anybody know if such a function exists in R?

解决方案

?Reduce. Usage Reduce(f, x, init, right = FALSE, accumulate = FALSE)

这篇关于F中的FoldLeft函数是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆