Re: [R] Saving output in an iterated function

2009-06-21 Thread Gabor Grothendieck
Extend it like this: Try this: f <- function(d, endPeriod) with(d, { period <- period + 1 ce <- eh + be de <- (eh + be)^2 ee <- ifelse(ce > de, de, ce) eh <- ifelse(period < endPeriod, ce, eh) data.fra

Re: [R] Saving output in an iterated function

2009-06-21 Thread Economics Guy
Unfortunately my actual function is a bit more complicated than "ce=ce+be" and does many transformations on the original vectors. Maybe something like this better conveys what I am trying to do: functM <- function(eh,be,period,endPeriod){ period <- period+1 ce <- eh+be de <

Re: [R] Saving output in an iterated function

2009-06-21 Thread Gabor Grothendieck
Try Reduce: f <- function(d, incr = 1) with(d, data.frame(eh = ce, be, ce = ce + be, period = period + incr)) d <- data.frame(ce = ones, be = twos, period = 0) Reduce(f, init = d, x = rep(1, 4)) Reduce(f, init = d, x = rep(1, 4), accumulate = TRUE) On Sun, Jun 21, 2009 at 9:06 AM, Econom

[R] Saving output in an iterated function

2009-06-21 Thread Economics Guy
# I have a function that takes a few vectors manipulates them and then outputs a matrix of results: funct1 <- function(eh,be){ ce <- eh+be data.frame(eh,be,ce) } ones <- c(1,1,1) twos <- c(2,2,2) funct1(ones,twos) # I would like to iterate it and save the results