[R] Evaluate a function for various value of parameters

Stephane DRAY dray at biomserv.univ-lyon1.fr
Sat Oct 23 00:10:44 CEST 2004

Hello list,

I have a problem ... and do not know how to solve it.
I would like create a function that estimate the quality of the fit of 
different functions with different values of parameters.
This problem is related to the following one:
I would like to create a function "evaluatemyfunction" which evaluate a 
function f for different values of parameters. For instance, if
f=function(a,b) a*b
evaluatemyfunction(f,1:10,5) would return:

I would like that f could have a variable number of arguments. I have begin 
to write a function:

myg=expand.grid(lapply(b,eval)) #contains all combinations of parameters
for (i in 1:nrow(myg)){

# ??????


I have try to construct arguments of the function as character, then parse 
and pass it to f but parse doesn't work:

 > parse(text=paste(paste(names(myg),myg[i,],sep="="),collapse=","))
Error in parse(file, n, text, prompt) : parse error

Any ideas ??

Thanks in advance,

Stéphane DRAY

Département des Sciences Biologiques
Université de Montréal, C.P. 6128, succursale centre-ville
Montréal, Québec H3C 3J7, Canada

Tel : (514) 343-6111 poste 1233         Fax : (514) 343-2293
E-mail : stephane.dray at umontreal.ca

Web                                          http://www.steph280.freesurf.fr/

More information about the R-help mailing list