[R] Executing a Function in a Loop With a Changing Value for an Argument

Rick Bilonick rab at nauticom.net
Thu Oct 25 07:01:42 CEST 2007


I want to run a function in a loop and replace one of the arguments from
a large list each time through the loop. If I was writing it out
manually:

myfunc(x=var1)
myfunc(x=var2)
etc.

But I want to do this in a loop where x is replaced by a new name. 

Something like:

for(i in vars) { myfunc(x=i) }

where "vars" is a vector of names for items in a data.frame.

If I use "as.symbol" to create names, the evaluation never works
correctly. Is there a way to do this? Any suggestions would be
appreciated.

Rick B.



More information about the R-help mailing list