I'm relatively new to R and I'm stuck. I'm trying to construct a surface to optimize from a multivariate dataset. The dataset contains the response of a system to various stimuli. I am trying to optimize the mix of stimuli to maximize the response. To do so, I've interpolated the various datasets of type response vs. stimuli and I now have an array of functions "interps" whose length is the length of the array of the names of the various stimuli. I've also created a vector containing names for the stimuli, vars = x.1, x.2, x.3...
Anyway, each of the functions in interps depends only on one variable (obviously). I would like to construct a function, call it, "surface" which is essentially: surface(vars) = interps[[1]]vars[[1]] + interps[[2]]vars[[2]]+... I've tried constructing surface recursively in a for loop: surface <- function(vars){0} for(i in 1:length(vars)){ surface <- function(vars){surface(vars) + interps[[i]](vars[[i]])} } This results in an infinite recursion error...which I think I understand. Essentially, I'm trying to do the analog of something like i = i+1, but instead of adding integers, I want to add terms to a function. Any help is appreciated. -- View this message in context: http://r.789695.n4.nabble.com/Multivariate-function-from-univariate-functions-tp4502670p4502670.html Sent from the R help mailing list archive at Nabble.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.