[R] Repeating a function
helin_susam
helin.susam at gmail.com
Mon Apr 18 02:49:13 CEST 2011
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.
More information about the R-help
mailing list