On Wed, Nov 17, 2010 at 9:42 AM, William Dunlap <wdun...@tibco.com> wrote: > Don't fixate on avoiding loops. Bury them in a function > so you don't have to see them and then you just want something > that does the right thing quickly enough. (I'm assuming > this is not a homework/puzzle type problem where you are not > allowed to use loops). E.g., the following does the job (with > no error checking): > Ybar <- function(u, Y) { > result <- Y[[1]](u) > for(Yi in Y[-1]) result <- result + Yi(u) > result/length(Y) > }
Since all these functions get passed the same arguments, what about merging them all together into one function. It seems like this process could even be automated from the list, perhaps using body() somehow? FOO <- function(u) { ((sqrt(u)) + (sin(u)) + (1/2*u))/3 } integrate(FOO, 0, 1) Is there a reason not to do this? Josh > > You could probably shoehorn this into a call to Reduce but there > must be a for loop in Reduce. > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.