[R] simulation

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue May 1 11:45:40 CEST 2007


Dimitris Rizopoulos wrote:
> maybe you're looking for something like this:
>
> x <- rpois(999, 2000)
> y <- numeric(length(x))
> for (i in seq_along(x))
>      y[i] <- sum(exp(rgamma(x[i], scale = 2, shape = 0.5)))
>
>   
Or use sapply,
sapply(x, function(x) sum(exp(rgamma(x[i], scale = 2, shape = 0.5)) )

or even

replicate(999, sum(exp(rgamma(rpois(1,2000), scale = 2, shape = 0.5)) )



More information about the R-help mailing list