Skip to content
Prev 58460 / 398502 Next

fold right - recursive list (vector) operators

Dear MJ,

If I follow correctly what you want to do, then the following should
work:

foldr <- function(f, x){
      if (length(x) > 1) f(c(x[1], Recall(f, x[-1])))
      else f(x)
      }

For example,
[1] 12
[1] 12

I hope this helps,
 John

On Wed, 3 Nov 2004 22:59:11 +0100 (CET)
Mads Jeppe Tarp-Johansen <s02mjtj at math.ku.dk> wrote:
--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/