[R] calling functions

Erik Iverson eriki at ccbr.umn.edu
Thu Jul 15 19:42:52 CEST 2010



louisey wrote:
> Hello everyone!!
> 
> I have written a function in R and need to call it more than once say M
> times then take an average of my output. How would I tell R to automatically
> call my function many times instead of just the once? 
> 

The natural way will depend on what you're trying to do, and since you 
don't give us a reproducible example as the posting guide asks for, we 
can only guess.

There are for loops.
There are the apply series of functions. (?apply, ?lappy, ?mapply, etc.)
There is ?replicate.

You also might avoid having to call your function multiple times 
completely if you vectorize it.



More information about the R-help mailing list