Re: [R] Repeating a function

From: helin_susam <>
Date: Sun, 17 Apr 2011 17:49:13 -0700 (PDT)


try this;

output <- list()

times <- 1000

drift <-function(p0=0.4,N=40,ngen=55){

        p = p0
        for( i in 1:ngen){
                p = rbinom(1,2*N,p)/(2*N)
        return( p )

for(i in 1:times){
result <- drift(0.4, 40, 55)

output <- c(output, list(result))

Then, you can use the "output" with unlist() to do analysis. For example mean(unlist(output))


View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 18 Apr 2011 - 01:05:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 18 Apr 2011 - 01:40:31 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive