Re: [R] Repeating a function

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

Hi,

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))

Helin.

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive