[R] Repeating a function in R

Daniel Malter daniel at umd.edu
Sat Jul 2 20:57:23 CEST 2011


If you want to repeat an entire function, use replicate as in

replicate(15,sapply(1,function(x) runif(x)))

Here, sapply(1,function(x) runif(x)) draws on uniformly distributed
variable. replicate(15,...) is the wrapper function that tells to do this 15
times. The benefit here is that you can replicate a more complex function.
However, if you just need 1000 random draws, I would use the easier approach
I suggested above.

Best,
Daniel

--
View this message in context: http://r.789695.n4.nabble.com/Repeating-a-function-in-R-tp3640508p3640982.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list